|
|
1.1 root 1:
2: /******************************************************************************\
3: * This is a part of the Microsoft Source Code Samples.
4: * Copyright (C) 1993 Microsoft Corporation.
5: * All rights reserved.
6: * This source code is only intended as a supplement to
7: * Microsoft Development Tools and/or WinHelp documentation.
8: * See these sources for detailed information regarding the
9: * Microsoft samples programs.
10: \******************************************************************************/
11:
12: ///////////////////////////////////////////////////////
13: //
14: // InstSrv.c --
15: //
16: // This program demonstrates the use of the OpenSCManager and
17: // CreateService APIs to install the Simple service sample.
18: //
19: #include <windows.h>
20: #include <stdio.h>
21: #include <stdlib.h>
22: #include <string.h>
23:
24: SC_HANDLE schService;
25: SC_HANDLE schSCManager;
26:
27: VOID
28: InstallService(LPCTSTR serviceName, LPCTSTR serviceExe)
29: {
30: LPCTSTR lpszBinaryPathName = serviceExe;
31:
32: schService = CreateService(
33: schSCManager, // SCManager database
34: serviceName, // name of service
35: serviceName, // name to display (new parameter after october beta)
36: SERVICE_ALL_ACCESS, // desired access
37: SERVICE_WIN32_OWN_PROCESS, // service type
38: SERVICE_DEMAND_START, // start type
39: SERVICE_ERROR_NORMAL, // error control type
40: lpszBinaryPathName, // service's binary
41: NULL, // no load ordering group
42: NULL, // no tag identifier
43: NULL, // no dependencies
44: NULL, // LocalSystem account
45: NULL); // no password
46:
47: if (schService == NULL) {
48: printf("failure: CreateService (0x%02x)\n", GetLastError());
49: return;
50: } else
51: printf("CreateService SUCCESS\n");
52:
53: CloseServiceHandle(schService);
54: }
55:
56: VOID
57: RemoveService(LPCTSTR serviceName)
58: {
59: BOOL ret;
60:
61: schService = OpenService(schSCManager, serviceName, SERVICE_ALL_ACCESS);
62:
63: if (schService == NULL) {
64: printf("failure: OpenService (0x%02x)\n", GetLastError());
65: return;
66: }
67:
68: ret = DeleteService(schService);
69:
70: if (ret)
71: printf("DeleteService SUCCESS\n");
72: else
73: printf("failure: DeleteService (0x%02x)\n", GetLastError());
74: }
75:
76: VOID
77: main(int argc, char *argv[])
78: {
79: if (argc != 3) {
80: printf("usage: instsrv <service name> <exe location>\n");
81: printf(" to install a service, or:\n");
82: printf(" instsrv <service name> remove\n");
83: printf(" to remove a service\n");
84: exit(1);
85: }
86:
87: schSCManager = OpenSCManager(
88: NULL, // machine (NULL == local)
89: NULL, // database (NULL == default)
90: SC_MANAGER_ALL_ACCESS // access required
91: );
92:
93: if (!stricmp(argv[2], "remove"))
94: RemoveService(argv[1]);
95: else
96: InstallService(argv[1], argv[2]);
97:
98: CloseServiceHandle(schSCManager);
99: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.