Ignore:
Timestamp:
08/17/10 11:23:57 (21 months ago)
Author:
jay
Message:

-- win32service application with start, stop, uninstall service, and start server normally integrated into one package. This is the initial commit for this approach.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/win32service/svcconfig/src/svcconfig.cpp

    r73 r78  
    33#include <strsafe.h> 
    44#include <stdio.h> 
     5#include "svcconfig.h" 
    56 
    67#pragma comment(lib, "advapi32.lib") 
    78 
    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); 
     9TCHAR szConfigCommand[TEXT_SIZE]; 
     10TCHAR szConfigSvcName[TEXT_SIZE]; 
     11 
    1812 
    1913// 
     
    2721//   None 
    2822// 
    29 void __cdecl _tmain(int argc, TCHAR *argv[]) 
    30 { 
     23//void __cdecl _tmain(int argc, TCHAR *argv[]) 
     24bool svcconfig (TCHAR * argv[]) 
     25{ 
     26        bool result = true; 
    3127    printf("\n"); 
     28        /* 
    3229    if( argc != 3 ) 
    3330    { 
     
    3633        return; 
    3734    } 
    38  
    39     StringCchCopy(szCommand, 10, argv[1]); 
    40     StringCchCopy(szSvcName, 80, argv[2]); 
    41  
    42     if (lstrcmpi( szCommand, TEXT("query")) == 0 ) 
    43         DoQuerySvc(); 
    44     else if (lstrcmpi( szCommand, 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 ) 
    4542        DoUpdateSvcDesc(); 
    46     else if (lstrcmpi( szCommand, TEXT("disable")) == 0 ) 
     43    else if (lstrcmpi( szConfigCommand, TEXT("disable")) == 0 ) 
    4744        DoDisableSvc(); 
    48     else if (lstrcmpi( szCommand, TEXT("enable")) == 0 ) 
     45    else if (lstrcmpi( szConfigCommand, TEXT("enable")) == 0 ) 
    4946        DoEnableSvc(); 
    50     else if (lstrcmpi( szCommand, TEXT("delete")) == 0 ) 
     47    else if (lstrcmpi( szConfigCommand, TEXT("uninstallService")) == 0 ) 
    5148        DoDeleteSvc(); 
    5249    else  
    5350    { 
    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/* 
    5958VOID __stdcall DisplayUsage() 
    6059{ 
     
    7069    printf("\t  delete\n"); 
    7170} 
    72  
     71*/ 
    7372// 
    7473// Purpose:  
     
    8180//   None 
    8281// 
    83 VOID __stdcall DoQuerySvc() 
     82bool __stdcall DoQuerySvc() 
    8483{ 
    8584    SC_HANDLE schSCManager; 
     
    9998    { 
    10099        printf("OpenSCManager failed (%d)\n", GetLastError()); 
    101         return; 
     100        return false; 
    102101    } 
    103102 
     
    106105    schService = OpenService(  
    107106        schSCManager,          // SCM database  
    108         szSvcName,             // name of service  
     107        szConfigSvcName,             // name of service  
    109108        SERVICE_QUERY_CONFIG); // need query config access  
    110109  
     
    113112        printf("OpenService failed (%d)\n", GetLastError());  
    114113        CloseServiceHandle(schSCManager); 
    115         return; 
     114        return false; 
    116115    } 
    117116 
     
    133132        { 
    134133            printf("QueryServiceConfig failed (%d)", dwError); 
     134                        return false; 
    135135            goto cleanup;  
    136136        } 
     
    144144    { 
    145145        printf("QueryServiceConfig failed (%d)", GetLastError()); 
     146                return false; 
    146147        goto cleanup; 
    147148    } 
     
    163164        { 
    164165            printf("QueryServiceConfig2 failed (%d)", dwError); 
     166                        return false; 
    165167            goto cleanup;  
    166168        } 
     
    175177    { 
    176178        printf("QueryServiceConfig2 failed (%d)", GetLastError()); 
     179                return false; 
    177180        goto cleanup; 
    178181    } 
     
    180183    // Print the configuration information. 
    181184  
    182     _tprintf(TEXT("%s configuration: \n"), szSvcName); 
     185    _tprintf(TEXT("%s configuration: \n"), szConfigSvcName); 
    183186    _tprintf(TEXT("  Type: 0x%x\n"), lpsc->dwServiceType); 
    184187    _tprintf(TEXT("  Start Type: 0x%x\n"), lpsc->dwStartType); 
     
    198201    LocalFree(lpsc);  
    199202    LocalFree(lpsd); 
    200  
     203        return true; 
    201204cleanup: 
    202205    CloseServiceHandle(schService);  
     
    236239    schService = OpenService(  
    237240        schSCManager,            // SCM database  
    238         szSvcName,               // name of service  
     241        szConfigSvcName,               // name of service  
    239242        SERVICE_CHANGE_CONFIG);  // need change config access  
    240243  
     
    301304    schService = OpenService(  
    302305        schSCManager,            // SCM database  
    303         szSvcName,               // name of service  
     306        szConfigSvcName,               // name of service  
    304307        SERVICE_CHANGE_CONFIG);  // need change config access  
    305308  
     
    368371    schService = OpenService(  
    369372        schSCManager,            // SCM database  
    370         szSvcName,               // name of service  
     373        szConfigSvcName,               // name of service  
    371374        SERVICE_CHANGE_CONFIG);  // need change config access  
    372375  
     
    428431    schService = OpenService(  
    429432        schSCManager,       // SCM database  
    430         szSvcName,          // name of service  
     433        szConfigSvcName,          // name of service  
    431434        DELETE);            // need delete access  
    432435  
Note: See TracChangeset for help on using the changeset viewer.