Changeset 78 for trunk/sources/win32service/svcconfig/src/svcconfig.cpp
- Timestamp:
- 08/17/10 11:23:57 (21 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/win32service/svcconfig/src/svcconfig.cpp
r73 r78 3 3 #include <strsafe.h> 4 4 #include <stdio.h> 5 #include "svcconfig.h" 5 6 6 7 #pragma comment(lib, "advapi32.lib") 7 8 8 TCHAR szCommand[10]; 9 TCHAR szSvcName[80]; 10 11 VOID __stdcall DisplayUsage(void); 12 13 VOID __stdcall DoQuerySvc(void); 14 VOID __stdcall DoUpdateSvcDesc(void); 15 VOID __stdcall DoDisableSvc(void); 16 VOID __stdcall DoEnableSvc(void); 17 VOID __stdcall DoDeleteSvc(void); 9 TCHAR szConfigCommand[TEXT_SIZE]; 10 TCHAR szConfigSvcName[TEXT_SIZE]; 11 18 12 19 13 // … … 27 21 // None 28 22 // 29 void __cdecl _tmain(int argc, TCHAR *argv[]) 30 { 23 //void __cdecl _tmain(int argc, TCHAR *argv[]) 24 bool svcconfig (TCHAR * argv[]) 25 { 26 bool result = true; 31 27 printf("\n"); 28 /* 32 29 if( argc != 3 ) 33 30 { … … 36 33 return; 37 34 } 38 39 StringCchCopy(szCo mmand, 10, argv[1]);40 StringCchCopy(sz SvcName, 80, argv[2]);41 42 if (lstrcmpi( szCo mmand, TEXT("query")) == 0 )43 DoQuerySvc();44 else if (lstrcmpi( szCo mmand, TEXT("describe")) == 0 )35 */ 36 StringCchCopy(szConfigCommand, TEXT_SIZE, argv[1]); 37 StringCchCopy(szConfigSvcName, TEXT_SIZE, argv[2]); 38 39 if (lstrcmpi( szConfigCommand, TEXT("query")) == 0 ) 40 result = DoQuerySvc(); 41 else if (lstrcmpi( szConfigCommand, TEXT("describe")) == 0 ) 45 42 DoUpdateSvcDesc(); 46 else if (lstrcmpi( szCo mmand, TEXT("disable")) == 0 )43 else if (lstrcmpi( szConfigCommand, TEXT("disable")) == 0 ) 47 44 DoDisableSvc(); 48 else if (lstrcmpi( szCo mmand, TEXT("enable")) == 0 )45 else if (lstrcmpi( szConfigCommand, TEXT("enable")) == 0 ) 49 46 DoEnableSvc(); 50 else if (lstrcmpi( szCo mmand, TEXT("delete")) == 0 )47 else if (lstrcmpi( szConfigCommand, TEXT("uninstallService")) == 0 ) 51 48 DoDeleteSvc(); 52 49 else 53 50 { 54 _tprintf(TEXT("Unknown command (%s)\n\n"), szCommand); 55 DisplayUsage(); 56 } 57 } 58 51 _tprintf(TEXT("Unknown command (%s)\n\n"), szConfigCommand); 52 //DisplayUsage(); 53 } 54 55 return result; 56 } 57 /* 59 58 VOID __stdcall DisplayUsage() 60 59 { … … 70 69 printf("\t delete\n"); 71 70 } 72 71 */ 73 72 // 74 73 // Purpose: … … 81 80 // None 82 81 // 83 VOID__stdcall DoQuerySvc()82 bool __stdcall DoQuerySvc() 84 83 { 85 84 SC_HANDLE schSCManager; … … 99 98 { 100 99 printf("OpenSCManager failed (%d)\n", GetLastError()); 101 return ;100 return false; 102 101 } 103 102 … … 106 105 schService = OpenService( 107 106 schSCManager, // SCM database 108 sz SvcName, // name of service107 szConfigSvcName, // name of service 109 108 SERVICE_QUERY_CONFIG); // need query config access 110 109 … … 113 112 printf("OpenService failed (%d)\n", GetLastError()); 114 113 CloseServiceHandle(schSCManager); 115 return ;114 return false; 116 115 } 117 116 … … 133 132 { 134 133 printf("QueryServiceConfig failed (%d)", dwError); 134 return false; 135 135 goto cleanup; 136 136 } … … 144 144 { 145 145 printf("QueryServiceConfig failed (%d)", GetLastError()); 146 return false; 146 147 goto cleanup; 147 148 } … … 163 164 { 164 165 printf("QueryServiceConfig2 failed (%d)", dwError); 166 return false; 165 167 goto cleanup; 166 168 } … … 175 177 { 176 178 printf("QueryServiceConfig2 failed (%d)", GetLastError()); 179 return false; 177 180 goto cleanup; 178 181 } … … 180 183 // Print the configuration information. 181 184 182 _tprintf(TEXT("%s configuration: \n"), sz SvcName);185 _tprintf(TEXT("%s configuration: \n"), szConfigSvcName); 183 186 _tprintf(TEXT(" Type: 0x%x\n"), lpsc->dwServiceType); 184 187 _tprintf(TEXT(" Start Type: 0x%x\n"), lpsc->dwStartType); … … 198 201 LocalFree(lpsc); 199 202 LocalFree(lpsd); 200 203 return true; 201 204 cleanup: 202 205 CloseServiceHandle(schService); … … 236 239 schService = OpenService( 237 240 schSCManager, // SCM database 238 sz SvcName, // name of service241 szConfigSvcName, // name of service 239 242 SERVICE_CHANGE_CONFIG); // need change config access 240 243 … … 301 304 schService = OpenService( 302 305 schSCManager, // SCM database 303 sz SvcName, // name of service306 szConfigSvcName, // name of service 304 307 SERVICE_CHANGE_CONFIG); // need change config access 305 308 … … 368 371 schService = OpenService( 369 372 schSCManager, // SCM database 370 sz SvcName, // name of service373 szConfigSvcName, // name of service 371 374 SERVICE_CHANGE_CONFIG); // need change config access 372 375 … … 428 431 schService = OpenService( 429 432 schSCManager, // SCM database 430 sz SvcName, // name of service433 szConfigSvcName, // name of service 431 434 DELETE); // need delete access 432 435
Note: See TracChangeset
for help on using the changeset viewer.
