winnt-nsis-installer-20030825
[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                 hService = CreateService(hSCM, argv[1],
33                 _T(argv[3]),
34                 SERVICE_ALL_ACCESS,
35                 SERVICE_WIN32_OWN_PROCESS,
36                 SERVICE_AUTO_START,
37                 SERVICE_ERROR_IGNORE,
38                 argv[2],
39                 NULL,NULL,NULL, NULL, NULL );
40
41         if (hService == NULL)
42         {
43                 printf("Create Service failed (%d)\n", GetLastError() );
44                 CloseServiceHandle(hSCM);
45         }
46
47         CloseServiceHandle(hService);
48
49
50         CloseServiceHandle(hService);
51         CloseServiceHandle(hSCM);
52
53         return 0;
54 }