├── .gitignore ├── README.org ├── winsearch.vcxproj.filters ├── winsearch.sln ├── winsearch.cpp └── winsearch.vcxproj /.gitignore: -------------------------------------------------------------------------------- 1 | .vs 2 | Debug 3 | Release 4 | winsearch.vcxproj.user 5 | -------------------------------------------------------------------------------- /README.org: -------------------------------------------------------------------------------- 1 | * Windows Search Command 2 | 3 | ** Usage 4 | =Usage: winsearch keyword...= 5 | 6 | ** Related Project 7 | 8 | [[https://github.com/misohena/adoquery][misohena/adoquery: Windows ADO Query Command]] 9 | -------------------------------------------------------------------------------- /winsearch.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | ソース ファイル 20 | 21 | 22 | -------------------------------------------------------------------------------- /winsearch.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.168 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "winsearch", "winsearch.vcxproj", "{1D4D031D-6846-4779-87BA-82216F08B9C4}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {1D4D031D-6846-4779-87BA-82216F08B9C4}.Debug|x64.ActiveCfg = Debug|x64 17 | {1D4D031D-6846-4779-87BA-82216F08B9C4}.Debug|x64.Build.0 = Debug|x64 18 | {1D4D031D-6846-4779-87BA-82216F08B9C4}.Debug|x86.ActiveCfg = Debug|Win32 19 | {1D4D031D-6846-4779-87BA-82216F08B9C4}.Debug|x86.Build.0 = Debug|Win32 20 | {1D4D031D-6846-4779-87BA-82216F08B9C4}.Release|x64.ActiveCfg = Release|x64 21 | {1D4D031D-6846-4779-87BA-82216F08B9C4}.Release|x64.Build.0 = Release|x64 22 | {1D4D031D-6846-4779-87BA-82216F08B9C4}.Release|x86.ActiveCfg = Release|Win32 23 | {1D4D031D-6846-4779-87BA-82216F08B9C4}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {B06A3EB7-7FFB-408A-9E9D-8F11BF66E910} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /winsearch.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Windows Search command-line client Visual C++ port 4 | * @author AKIYAMA Kouhei 5 | * @since 2010-07-01 6 | * 7 | * Original python script is: 8 | * http://www.carcosa.net/jason/software/utilities/desktopsearch/ (Jason F. McBrayer) 9 | * 10 | */ 11 | #import "c:\Program Files\Common Files\System\ADO\msado15.dll" rename("EOF", "ADO_EOF") 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | //typedef ADODB::_ConnectionPtr ADOConnectionPtr; 25 | //typedef ADODB::_RecordsetPtr ADORecordsetPtr; 26 | //typedef ADODB::ErrorPtr ADOErrorPtr; 27 | //typedef ADODB::_CommandPtr ADOCommandPtr; 28 | //typedef ADODB::_ParameterPtr ADOParameterPtr; 29 | //typedef ADODB::FieldPtr ADOFieldPtr; 30 | 31 | // main 32 | int _tmain(int argc, TCHAR *argv[]) 33 | { 34 | const int maxResultCount = 30; 35 | if(argc <= 1){ 36 | _tprintf(_T("Usage: winsearch keyword...\n")); 37 | return -1; 38 | } 39 | 40 | // set locale 41 | setlocale(LC_ALL, ""); 42 | 43 | // create query 44 | static const TCHAR * const COLUMN_FILE_DIR = _T("System.ItemFolderPathDisplay"); 45 | static const TCHAR * const COLUMN_FILE_NAME = _T("System.FileName"); 46 | using string = std::basic_string; 47 | 48 | string query_names; 49 | string query_contains; 50 | for(int ai = 1; ai < argc; ++ai){ 51 | if(ai > 1){ 52 | query_names += _T(" AND "); 53 | query_contains += _T(" AND "); 54 | } 55 | query_names += _T("System.FileName Like '%") + string(argv[ai]) + _T("%'"); ///@todo escape 56 | query_contains += _T("Contains('\"") + string(argv[ai]) + _T("\"')"); ///@todo escape 57 | } 58 | string query 59 | = string(_T("SELECT ")) 60 | + COLUMN_FILE_DIR + _T(",") 61 | + COLUMN_FILE_NAME 62 | + _T(" FROM SYSTEMINDEX") 63 | + _T(" WHERE (") 64 | + query_names + _T(" ) OR ( ") + query_contains + _T(" )"); 65 | 66 | // initialize COM 67 | ::CoInitialize(NULL); 68 | // search 69 | ADODB::_ConnectionPtr conn; 70 | try{ 71 | if(conn.CreateInstance(__uuidof(ADODB::Connection)) == S_OK){ 72 | // open 73 | conn->Open( 74 | _T("Provider=Search.CollatorDSO;Extended Properties='Application=Windows';"), 75 | _T(""), //UserID 76 | _T(""), //Password 77 | NULL); 78 | 79 | // execute 80 | ADODB::_RecordsetPtr recordset = conn->Execute(query.c_str(), NULL, ADODB::adCmdText); 81 | 82 | // enumerate 83 | if(! (recordset->GetBOF() && recordset->GetADO_EOF()) ){ 84 | recordset->MoveFirst(); 85 | 86 | int count = 0; 87 | const _variant_t varColumnFileDir = COLUMN_FILE_DIR; 88 | const _variant_t varColumnFileName = COLUMN_FILE_NAME; 89 | while( ! recordset->ADO_EOF && count < maxResultCount){ 90 | _tprintf(_T("%s\\%s\n"), 91 | (recordset->Fields->GetItem(varColumnFileDir )->GetValue()).bstrVal, 92 | (recordset->Fields->GetItem(varColumnFileName)->GetValue()).bstrVal 93 | ); 94 | recordset->MoveNext(); 95 | ++count; 96 | } 97 | } 98 | 99 | } 100 | else{ 101 | _ftprintf(stderr, _T("Error: Failed to connect database\n")); 102 | } 103 | }catch(_com_error &e){ 104 | _ftprintf(stderr, _T("Error: (0x%08x):%s\n"), e.Error() , (LPWSTR)e.Description()); 105 | } 106 | 107 | // close 108 | if(conn && conn->State != ADODB::adStateClosed){ 109 | conn->Close(); 110 | } 111 | 112 | ::CoUninitialize(); 113 | 114 | return 0; 115 | } 116 | -------------------------------------------------------------------------------- /winsearch.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 15.0 23 | {1D4D031D-6846-4779-87BA-82216F08B9C4} 24 | Win32Proj 25 | winsearch 26 | 10.0.17763.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v141 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v141 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v141 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v141 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | 76 | 77 | true 78 | 79 | 80 | false 81 | 82 | 83 | false 84 | 85 | 86 | 87 | Level3 88 | Disabled 89 | true 90 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 91 | true 92 | 93 | 94 | true 95 | Console 96 | 97 | 98 | 99 | 100 | Level3 101 | Disabled 102 | true 103 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 104 | true 105 | 106 | 107 | true 108 | Console 109 | 110 | 111 | 112 | 113 | Level3 114 | MaxSpeed 115 | true 116 | true 117 | true 118 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 119 | true 120 | 121 | 122 | true 123 | true 124 | true 125 | Console 126 | 127 | 128 | 129 | 130 | Level3 131 | MaxSpeed 132 | true 133 | true 134 | true 135 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 136 | true 137 | 138 | 139 | true 140 | true 141 | true 142 | Console 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | --------------------------------------------------------------------------------