release-1370-20040810
[openafs.git] / src / WINNT / install / NSIS / Service.cpp
1 /*
2       Service Installer for NSIS script
3       
4       Rob Murawski
5       
6       Released under terms of IBM Open Source agreement for OpenAFS
7       
8       */
9
10 #include <stdio.h>
11 #include <windows.h>
12 #include <tchar.h>
13
14 int main(int argc, char *argv[])
15 {
16    if(argc<3)
17    {
18       printf("Insufficient arguments: Service ServiceName ServicePath DisplayName.\n");
19       return 1;
20    }
21    
22         SC_HANDLE hSCM = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE);
23         SC_HANDLE hService;
24
25         if(hSCM == NULL)
26         {
27                 printf("Could not open Service Control Manager. Aborting.\n");
28                 return 1;
29         }
30
31
32    if(*argv[1]!='u' && *argv[1]!='U')
33    {
34                 hService = CreateService(hSCM, argv[1],
35                 _T(argv[3]),
36                 SERVICE_ALL_ACCESS,
37                 SERVICE_WIN32_OWN_PROCESS,
38                 SERVICE_AUTO_START,
39                 SERVICE_ERROR_IGNORE,
40                 argv[2],
41                 NULL,NULL,NULL, NULL, NULL );
42
43                 if (hService == NULL) 
44                 {
45                     printf("Create Service failed (%d)\n", GetLastError() );
46                     CloseServiceHandle(hSCM);
47                 }
48    }
49    else
50    {
51        hService = OpenService( hSCM, argv[2], DELETE);
52        if(hService!=NULL)
53            DeleteService( hService );
54    }
55    
56         CloseServiceHandle(hService);
57
58
59         CloseServiceHandle(hService);
60         CloseServiceHandle(hSCM);
61
62         return 0;
63 }