ReactOS 0.4.16-dev-252-g9ccafe8
sc.h File Reference
#include <stdarg.h>
#include <windef.h>
#include <winbase.h>
#include <winsvc.h>
#include <sddl.h>
#include <tchar.h>
#include <ndk/rtlfuncs.h>
#include <ndk/setypes.h>
Include dependency graph for sc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  SERVICE_CREATE_INFO
 

Macros

#define WIN32_NO_STATUS
 

Typedefs

typedef struct SERVICE_CREATE_INFOLPSERVICE_CREATE_INFO
 

Functions

BOOL Start (LPCTSTR ServiceName, LPCTSTR *ServiceArgs, INT ArgCount)
 
BOOL Create (LPCTSTR *ServiceArgs, INT ArgCount)
 
BOOL Delete (LPCTSTR ServiceName)
 
BOOL Control (DWORD Control, LPCTSTR ServiceName, LPCTSTR *Args, INT ArgCount)
 
BOOL Query (LPCTSTR *ServiceArgs, DWORD ArgCount, BOOL bExtended)
 
LPSERVICE_STATUS_PROCESS QueryService (LPCTSTR ServiceName)
 
BOOL SdShow (LPCTSTR ServiceName)
 
BOOL SdSet (LPCTSTR ServiceName, LPCTSTR SecurityDescriptor)
 
BOOL QueryConfig (LPCTSTR ServiceName)
 
BOOL SetConfig (LPCTSTR *ServiceArgs, INT ArgCount)
 
BOOL QueryDescription (LPCTSTR ServiceName)
 
BOOL SetDescription (LPCTSTR ServiceName, LPCTSTR Description)
 
BOOL QueryFailure (LPCTSTR ServiceName)
 
BOOL SetFailure (LPCTSTR *ServiceArgs, INT ArgCount)
 
BOOL GetDisplayName (LPCTSTR ServiceName)
 
BOOL GetKeyName (LPCTSTR ServiceName)
 
BOOL EnumDepend (LPCTSTR ServiceName)
 
VOID PrintService (LPCTSTR ServiceName, LPCTSTR DisplayName, LPSERVICE_STATUS_PROCESS pStatus, BOOL bExtended)
 
VOID PrintServiceStatus (LPSERVICE_STATUS pStatus)
 
VOID ReportLastError (VOID)
 
BOOL ParseCreateConfigArguments (LPCTSTR *ServiceArgs, INT ArgCount, BOOL bChangeService, OUT LPSERVICE_CREATE_INFO lpServiceInfo)
 
BOOL ParseFailureArguments (LPCTSTR *ServiceArgs, INT ArgCount, OUT LPCTSTR *ppServiceName, OUT LPSERVICE_FAILURE_ACTIONS pFailureActions)
 
VOID MainUsage (VOID)
 
VOID StartUsage (VOID)
 
VOID PauseUsage (VOID)
 
VOID InterrogateUsage (VOID)
 
VOID ContinueUsage (VOID)
 
VOID StopUsage (VOID)
 
VOID DeleteUsage (VOID)
 
VOID CreateUsage (VOID)
 
VOID ControlUsage (VOID)
 
VOID SdShowUsage (VOID)
 
VOID SdSetUsage (VOID)
 
VOID QueryConfigUsage (VOID)
 
VOID QueryDescriptionUsage (VOID)
 
VOID QueryFailureUsage (VOID)
 
VOID SetDescriptionUsage (VOID)
 
VOID SetConfigUsage (VOID)
 
VOID SetFailureUsage (VOID)
 
VOID GetDisplayNameUsage (VOID)
 
VOID GetKeyNameUsage (VOID)
 
VOID EnumDependUsage (VOID)
 

Macro Definition Documentation

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 6 of file sc.h.

Typedef Documentation

◆ LPSERVICE_CREATE_INFO

Function Documentation

◆ ContinueUsage()

VOID ContinueUsage ( VOID  )

Definition at line 127 of file usage.c.

128{
129 _tprintf(_T("DESCRIPTION:\n")
130 _T(" Sends a CONTINUE control request to a service.\n")
131 _T("USAGE:\n")
132 _T(" sc <server> continue [service name]\n"));
133}
#define _tprintf
Definition: tchar.h:506
#define _T(x)
Definition: vfdio.h:22

Referenced by ScControl().

◆ Control()

BOOL Control ( DWORD  Control,
LPCTSTR  ServiceName,
LPCTSTR Args,
INT  ArgCount 
)

Definition at line 13 of file control.c.

17{
18 SC_HANDLE hSCManager = NULL;
19 SC_HANDLE hService = NULL;
21 DWORD dwDesiredAccess = 0;
22 BOOL bResult = TRUE;
24
25#ifdef SCDBG
26 LPCTSTR *TmpArgs = Args;
27 INT TmpCnt = ArgCount;
28 _tprintf(_T("service to control - %s\n"), ServiceName);
29 _tprintf(_T("command - %lu\n"), Control);
30 _tprintf(_T("Arguments:\n"));
31 while (TmpCnt)
32 {
33 _tprintf(_T(" %s\n"), *TmpArgs);
34 TmpArgs++;
35 TmpCnt--;
36 }
37 _tprintf(_T("\n"));
38#endif /* SCDBG */
39
40 switch (Control)
41 {
43 dwDesiredAccess = SERVICE_STOP;
44 break;
45
53 dwDesiredAccess = SERVICE_PAUSE_CONTINUE;
54 break;
55
57 dwDesiredAccess = SERVICE_INTERROGATE;
58 break;
59
60 default:
61 if (Control >= 128 && Control <= 255)
62 dwDesiredAccess = SERVICE_USER_DEFINED_CONTROL;
63 else
64 dwDesiredAccess = 0;
65 break;
66 }
67
69 NULL,
71 if (hSCManager == NULL)
72 {
73 _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
74 bResult = FALSE;
75 goto done;
76 }
77
78 hService = OpenService(hSCManager,
80 dwDesiredAccess);
81 if (hService == NULL)
82 {
83 _tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError());
84 bResult = FALSE;
85 goto done;
86 }
87
88 if (!ControlService(hService,
89 Control,
90 &Status))
91 {
92 _tprintf(_T("[SC] ControlService FAILED %lu:\n\n"), GetLastError());
93 bResult = FALSE;
94 goto done;
95 }
96
97 /* FIXME: lazy hack ;) */
98 CopyMemory(&StatusEx, &Status, sizeof(Status));
99 StatusEx.dwProcessId = 0;
100 StatusEx.dwServiceFlags = 0;
101
103 NULL,
104 &StatusEx,
105 FALSE);
106
107done:
108 if (!bResult)
110
111 if (hService)
112 CloseServiceHandle(hService);
113
114 if (hSCManager)
116
117 return bResult;
118}
char ** Args
Definition: acdebug.h:353
VOID PrintService(LPCTSTR lpServiceName, LPCTSTR lpDisplayName, LPSERVICE_STATUS_PROCESS pStatus, BOOL bExtended)
Definition: print.c:13
static WCHAR ServiceName[]
Definition: browser.c:19
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
Status
Definition: gdiplustypes.h:25
DWORD ReportLastError(void)
Definition: loadlib.c:67
SC_HANDLE hSCManager
Definition: sc.c:12
BOOL WINAPI ControlService(SC_HANDLE hService, DWORD dwControl, LPSERVICE_STATUS lpServiceStatus)
Definition: scm.c:622
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:580
int32_t INT
Definition: typedefs.h:58
_In_ WDF_WMI_PROVIDER_CONTROL Control
Definition: wdfwmi.h:166
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define CopyMemory
Definition: winbase.h:1735
#define SERVICE_CONTROL_PARAMCHANGE
Definition: winsvc.h:41
#define SERVICE_CONTROL_NETBINDREMOVE
Definition: winsvc.h:43
#define SERVICE_CONTROL_NETBINDADD
Definition: winsvc.h:42
#define OpenSCManager
Definition: winsvc.h:575
#define SERVICE_USER_DEFINED_CONTROL
Definition: winsvc.h:61
#define SC_MANAGER_CONNECT
Definition: winsvc.h:14
#define SERVICE_CONTROL_NETBINDDISABLE
Definition: winsvc.h:45
#define SERVICE_PAUSE_CONTINUE
Definition: winsvc.h:59
#define SERVICE_CONTROL_NETBINDENABLE
Definition: winsvc.h:44
#define SERVICE_INTERROGATE
Definition: winsvc.h:60
#define SERVICE_STOP
Definition: winsvc.h:58
#define SERVICE_CONTROL_CONTINUE
Definition: winsvc.h:38
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36
#define SERVICE_CONTROL_PAUSE
Definition: winsvc.h:37
#define SERVICE_CONTROL_INTERROGATE
Definition: winsvc.h:39
#define OpenService
Definition: winsvc.h:576
const CHAR * LPCTSTR
Definition: xmlstorage.h:193

◆ ControlUsage()

VOID ControlUsage ( VOID  )

Definition at line 169 of file usage.c.

170{
171 _tprintf(_T("DESCRIPTION:\n")
172 _T(" Sends a CONTROL code to a service.\n")
173 _T("USAGE:\n")
174 _T(" sc <server> control [service name] <value>\n")
175 _T(" <value> = user-defined control code\n")
176 _T(" <value> = <paramchange|\n")
177 _T(" netbindadd|netbindremove|\n")
178 _T(" netbindenable|netbinddisable>\n"));
179}

Referenced by ScControl().

◆ Create()

BOOL Create ( LPCTSTR ServiceArgs,
INT  ArgCount 
)

Definition at line 13 of file create.c.

14{
15 SC_HANDLE hSCManager = NULL;
16 SC_HANDLE hService = NULL;
17 BOOL bRet = TRUE;
18
19 INT i;
20 INT Length;
23
24 if (!ParseCreateConfigArguments(ServiceArgs, ArgCount, FALSE, &ServiceInfo))
25 {
27 return FALSE;
28 }
29
30 if (!ServiceInfo.dwServiceType)
32
33 if (!ServiceInfo.dwStartType)
35
36 if (!ServiceInfo.dwErrorControl)
37 ServiceInfo.dwErrorControl = SERVICE_ERROR_NORMAL;
38
39 if (ServiceInfo.lpDependencies)
40 {
41 Length = lstrlen(ServiceInfo.lpDependencies);
42
44 0,
45 (Length + 2) * sizeof(TCHAR));
46
47 for (i = 0; i < Length; i++)
48 if (ServiceInfo.lpDependencies[i] == _T('/'))
49 lpBuffer[i] = 0;
50 else
51 lpBuffer[i] = ServiceInfo.lpDependencies[i];
52
53 lpBuffer[Length] = 0;
54 lpBuffer[Length + 1] = 0;
55
56 ServiceInfo.lpDependencies = lpBuffer;
57 }
58
59#ifdef SCDBG
60 _tprintf(_T("service name - %s\n"), ServiceInfo.lpServiceName);
61 _tprintf(_T("display name - %s\n"), ServiceInfo.lpDisplayName);
62 _tprintf(_T("service type - %lu\n"), ServiceInfo.dwServiceType);
63 _tprintf(_T("start type - %lu\n"), ServiceInfo.dwStartType);
64 _tprintf(_T("error control - %lu\n"), ServiceInfo.dwErrorControl);
65 _tprintf(_T("Binary path - %s\n"), ServiceInfo.lpBinaryPathName);
66 _tprintf(_T("load order group - %s\n"), ServiceInfo.lpLoadOrderGroup);
67 _tprintf(_T("tag - %lu\n"), ServiceInfo.dwTagId);
68 _tprintf(_T("dependencies - %s\n"), ServiceInfo.lpDependencies);
69 _tprintf(_T("account start name - %s\n"), ServiceInfo.lpServiceStartName);
70 _tprintf(_T("account password - %s\n"), ServiceInfo.lpPassword);
71#endif
72
74 if (hSCManager == NULL)
75 {
76 _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
77 bRet = FALSE;
78 goto done;
79 }
80
81 hService = CreateService(hSCManager,
82 ServiceInfo.lpServiceName,
83 ServiceInfo.lpDisplayName,
85 ServiceInfo.dwServiceType,
86 ServiceInfo.dwStartType,
87 ServiceInfo.dwErrorControl,
88 ServiceInfo.lpBinaryPathName,
89 ServiceInfo.lpLoadOrderGroup,
90 ServiceInfo.bTagId ? &ServiceInfo.dwTagId : NULL,
91 ServiceInfo.lpDependencies,
92 ServiceInfo.lpServiceStartName,
93 ServiceInfo.lpPassword);
94 if (hService == NULL)
95 {
96 _tprintf(_T("[SC] CreateService FAILED %lu:\n\n"), GetLastError());
97 bRet = FALSE;
98 goto done;
99 }
100
101 _tprintf(_T("[SC] CreateService SUCCESS\n\n"));
102
103done:
104 if (bRet == FALSE)
106
107 if (hService)
108 CloseServiceHandle(hService);
109
110 if (hSCManager)
112
113 if (lpBuffer != NULL)
115
116 return bRet;
117}
BOOL ParseCreateConfigArguments(LPCTSTR *ServiceArgs, INT ArgCount, BOOL bChangeService, OUT LPSERVICE_CREATE_INFO lpServiceInfo)
Definition: misc.c:53
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:175
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
VOID CreateUsage(VOID)
Definition: usage.c:146
JS_SERVICE_STATE ServiceInfo(LPCTSTR ServiceName)
Return service status by service name.
Definition: user_lib.cpp:157
#define lstrlen
Definition: winbase.h:3901
#define SERVICE_ALL_ACCESS
Definition: winsvc.h:62
#define CreateService
Definition: winsvc.h:569
#define SC_MANAGER_CREATE_SERVICE
Definition: winsvc.h:15
#define SERVICE_DEMAND_START
Definition: cmtypes.h:978
#define SERVICE_WIN32_OWN_PROCESS
Definition: cmtypes.h:962
#define SERVICE_ERROR_NORMAL
Definition: cmtypes.h:982
char TCHAR
Definition: xmlstorage.h:189
CHAR * LPTSTR
Definition: xmlstorage.h:192

◆ CreateUsage()

VOID CreateUsage ( VOID  )

Definition at line 146 of file usage.c.

147{
148 _tprintf(_T("Creates a service entry in the registry and Service Database.\n")
149 _T("SYNTAX:\n")
150 _T("sc create [service name] [binPath= ] <option1> <option2>...\n")
151 _T("CREATE OPTIONS:\n")
152 _T("NOTE: The option name includes the equal sign.\n")
153 _T(" type= <own|share|interact|kernel|filesys|rec>\n")
154 _T(" (default = own)\n")
155 _T(" start= <boot|system|auto|demand|disabled>\n")
156 _T(" (default = demand)\n")
157 _T(" error= <normal|severe|critical|ignore>\n")
158 _T(" (default = normal)\n")
159 _T(" binPath= <BinaryPathName>\n")
160 _T(" group= <LoadOrderGroup>\n")
161 _T(" tag= <yes|no>\n")
162 _T(" depend= <Dependencies(separated by / (forward slash))>\n")
163 _T(" obj= <AccountName|ObjectName>\n")
164 _T(" (default = LocalSystem)\n")
165 _T(" DisplayName= <display name>\n")
166 _T(" password= <password>\n"));
167}

Referenced by Create().

◆ Delete()

BOOL Delete ( LPCTSTR  ServiceName)

Definition at line 12 of file delete.c.

13{
14 SC_HANDLE hSCManager = NULL;
15 SC_HANDLE hSc = NULL;
16 BOOL bRet = TRUE;
17
18#ifdef SCDBG
19 _tprintf(_T("service to delete - %s\n\n"), ServiceName);
20#endif
21
23 NULL,
25 if (hSCManager == NULL)
26 {
27 _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
28 bRet = FALSE;
29 goto done;
30 }
31
33 if (hSc == NULL)
34 {
35 _tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError());
36 bRet = FALSE;
37 goto done;
38 }
39
40 if (!DeleteService(hSc))
41 {
42 _tprintf(_T("[SC] DeleteService FAILED %lu:\n\n"), GetLastError());
43 bRet = FALSE;
44 goto done;
45 }
46
47 _tprintf(_T("[SC] DeleteService SUCCESS\n\n"));
48
49done:
50 if (bRet == FALSE)
52
53 if (hSc)
55
56 if (hSCManager)
58
59 return bRet;
60}
#define DELETE
Definition: nt_native.h:57
BOOL WINAPI DeleteService(SC_HANDLE hService)
Definition: scm.c:921

Referenced by _CcpFlushCache(), cmdUse(), DECLARE_INTERFACE_(), PropertySetStorage_Delete(), RawCheckForDismount(), registry_callback(), ScControl(), test_SHPropStg_functions(), UDFCleanUpFcbChain(), UDFSetDispositionInformation(), UpdateRegistry(), and VfatCheckForDismount().

◆ DeleteUsage()

VOID DeleteUsage ( VOID  )

Definition at line 135 of file usage.c.

136{
137 _tprintf(_T("DESCRIPTION:\n")
138 _T(" Deletes a service entry from the registry.\n")
139 _T(" If the service is running, or another process has an\n")
140 _T(" open handle to the service, the service is simply marked\n")
141 _T(" for deletion.\n")
142 _T("USAGE:\n")
143 _T(" sc <server> delete [service name]\n"));
144}

Referenced by ScControl().

◆ EnumDepend()

BOOL EnumDepend ( LPCTSTR  ServiceName)

Definition at line 12 of file depend.c.

13{
14 SC_HANDLE hManager = NULL;
15 SC_HANDLE hService = NULL;
16 BOOL bResult = TRUE;
17 DWORD BufferSize = 0;
18 DWORD EntriesRead = 0;
20 DWORD i;
21
22 hManager = OpenSCManager(NULL,
23 NULL,
25 if (hManager == NULL)
26 {
27 _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
28 bResult = FALSE;
29 goto done;
30 }
31
33 if (hService == NULL)
34 {
35 _tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError());
36 bResult = FALSE;
37 goto done;
38 }
39
40 if (!EnumDependentServices(hService,
42 NULL,
43 0,
45 &EntriesRead))
46 {
47 if (BufferSize == 0)
48 {
49 _tprintf(_T("[SC] EnumDependentServices FAILED %lu:\n\n"), GetLastError());
50 bResult = FALSE;
51 goto done;
52 }
53 }
54
56 if (pBuffer == NULL)
57 {
59 _tprintf(_T("[SC] HeapAlloc FAILED %lu:\n\n"), GetLastError());
60 bResult = FALSE;
61 goto done;
62 }
63
64 if (!EnumDependentServices(hService,
66 pBuffer,
69 &EntriesRead))
70 {
71 _tprintf(_T("[SC] EnumDependentServices FAILED %lu:\n\n"), GetLastError());
72 bResult = FALSE;
73 goto done;
74 }
75
76 _tprintf(_T("Enum: entriesRead = %lu\n"), EntriesRead);
77
78 for (i = 0; i < EntriesRead; i++)
79 {
80 _tprintf(_T("\n"));
81 _tprintf(_T("SERVICE_NAME: %s\n"), pBuffer[i].lpServiceName);
82 _tprintf(_T("DISPLAY_NAME: %s\n"), pBuffer[i].lpDisplayName);
84 }
85
86done:
87 if (bResult == FALSE)
89
90 if (pBuffer != NULL)
92
93 if (hService)
94 CloseServiceHandle(hService);
95
96 if (hManager)
97 CloseServiceHandle(hManager);
98
99 return bResult;
100}
VOID PrintServiceStatus(LPSERVICE_STATUS pStatus)
Definition: print.c:39
static SERVICE_STATUS ServiceStatus
Definition: browser.c:22
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#define SetLastError(x)
Definition: compat.h:752
PVOID pBuffer
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254
_In_ LPCSTR _Out_writes_to_opt_ cchDisplayName LPSTR lpDisplayName
Definition: winbase.h:2815
#define SERVICE_STATE_ALL
Definition: winsvc.h:52
#define EnumDependentServices
Definition: winsvc.h:570
#define SERVICE_ENUMERATE_DEPENDENTS
Definition: winsvc.h:56

Referenced by ScControl().

◆ EnumDependUsage()

VOID EnumDependUsage ( VOID  )

Definition at line 285 of file usage.c.

286{
287 _tprintf(_T("DESCRIPTION:\n")
288 _T(" Enumerates te Services that are dependent on this one.\n")
289 _T("USAGE:\n")
290 _T(" sc <server> EnumDepend <service display name> <bufsize>\n"));
291}

Referenced by ScControl().

◆ GetDisplayName()

BOOL GetDisplayName ( LPCTSTR  ServiceName)

Definition at line 12 of file name.c.

13{
14 SC_HANDLE hManager = NULL;
15 BOOL bResult = TRUE;
16 DWORD BufferSize = 0;
18
19 hManager = OpenSCManager(NULL,
20 NULL,
22 if (hManager == NULL)
23 {
24 _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
25 bResult = FALSE;
26 goto done;
27 }
28
29 if (!GetServiceDisplayName(hManager,
31 NULL,
32 &BufferSize))
33 {
34 if (BufferSize == 0)
35 {
36 _tprintf(_T("[SC] GetServiceDisplayName FAILED %lu:\n\n"), GetLastError());
37 bResult = FALSE;
38 goto done;
39 }
40 }
41
42 pBuffer = HeapAlloc(GetProcessHeap(), 0, (BufferSize + 1) * sizeof(TCHAR));
43 if (pBuffer == NULL)
44 {
46 _tprintf(_T("[SC] HeapAlloc FAILED %lu:\n\n"), GetLastError());
47 bResult = FALSE;
48 goto done;
49 }
50
51 BufferSize++;
52 if (!GetServiceDisplayName(hManager,
54 pBuffer,
55 &BufferSize))
56 {
57 _tprintf(_T("[SC] GetServiceDisplayName FAILED %lu:\n\n"), GetLastError());
58 bResult = FALSE;
59 goto done;
60 }
61
62 _tprintf(_T("[SC] GetServiceDisplayName SUCCESS Name = %s\n"), pBuffer);
63
64done:
65 if (bResult == FALSE)
67
68 if (pBuffer != NULL)
70
71 if (hManager)
72 CloseServiceHandle(hManager);
73
74 return bResult;
75}
#define GetServiceDisplayName
Definition: winsvc.h:573

Referenced by _test_GetCurMoniker(), DECLARE_INTERFACE_(), Moniker_GetDisplayName(), ScControl(), test_editing_mode(), test_exec_editmode(), test_Hlink_Navigate(), test_HlinkGetSetMonikerReference(), test_HlinkResolveMonikerForData(), test_HlinkSite(), and test_Load().

◆ GetDisplayNameUsage()

VOID GetDisplayNameUsage ( VOID  )

Definition at line 268 of file usage.c.

269{
270 _tprintf(_T("DESCRIPTION:\n")
271 _T(" Gets the display name associated with a particular service.\n")
272 _T("USAGE:\n")
273 _T(" sc <server> GetDisplayName <service key name> <bufsize>\n"));
274}

Referenced by ScControl().

◆ GetKeyName()

BOOL GetKeyName ( LPCTSTR  ServiceName)

Definition at line 77 of file name.c.

78{
79 SC_HANDLE hManager = NULL;
80 BOOL bResult = TRUE;
81 DWORD BufferSize = 0;
83
84 hManager = OpenSCManager(NULL,
85 NULL,
87 if (hManager == NULL)
88 {
89 _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
90 bResult = FALSE;
91 goto done;
92 }
93
94 if (!GetServiceKeyName(hManager,
96 NULL,
97 &BufferSize))
98 {
99 if (BufferSize == 0)
100 {
101 _tprintf(_T("[SC] GetServiceKeyName FAILED %lu:\n\n"), GetLastError());
102 bResult = FALSE;
103 goto done;
104 }
105 }
106
107 pBuffer = HeapAlloc(GetProcessHeap(), 0, (BufferSize + 1) * sizeof(TCHAR));
108 if (pBuffer == NULL)
109 {
111 _tprintf(_T("[SC] HeapAlloc FAILED %lu:\n\n"), GetLastError());
112 bResult = FALSE;
113 goto done;
114 }
115
116 BufferSize++;
117 if (!GetServiceKeyName(hManager,
119 pBuffer,
120 &BufferSize))
121 {
122 _tprintf(_T("[SC] GetServiceKeyName FAILED %lu:\n\n"), GetLastError());
123 bResult = FALSE;
124 goto done;
125 }
126
127 _tprintf(_T("[SC] GetServiceKeyName SUCCESS Name = %s\n"), pBuffer);
128
129done:
130 if (bResult == FALSE)
132
133 if (pBuffer != NULL)
135
136 if (hManager)
137 CloseServiceHandle(hManager);
138
139 return bResult;
140}
#define GetServiceKeyName
Definition: winsvc.h:574

◆ GetKeyNameUsage()

VOID GetKeyNameUsage ( VOID  )

Definition at line 276 of file usage.c.

277{
278 _tprintf(_T("DESCRIPTION:\n")
279 _T(" Gets the key name associated with a particular service, using the\n")
280 _T(" display name as input.\n")
281 _T("USAGE:\n")
282 _T(" sc <server> GetKeyName <service display name> <bufsize>\n"));
283}

Referenced by ScControl().

◆ InterrogateUsage()

VOID InterrogateUsage ( VOID  )

Definition at line 110 of file usage.c.

111{
112 _tprintf(_T("DESCRIPTION:\n")
113 _T(" Sends an INTERROGATE control request to a service.\n")
114 _T("USAGE:\n")
115 _T(" sc <server> interrogate [service name]\n"));
116}

Referenced by ScControl().

◆ MainUsage()

VOID MainUsage ( VOID  )

Definition at line 14 of file usage.c.

15{
16 INT c;
17
18 _tprintf(_T("DESCRIPTION:\n")
19 _T("\tSC is a command line program used for communicating with\n")
20 _T("\tthe Service Control Manager and its services.\n")
21 _T("USAGE:\n")
22 _T("\tsc <server> [command] [service name] <option1> <option2>...\n")
23
24 _T("\tThe optional parameter <server> has the form \"\\ServerName\"\n")
25 _T("\tFurther help on commands can be obtained by typing: \"sc [command]\"\n")
26 _T("\tService Commands:\n")
27 _T("\t query : Queries the status for a service, or\n")
28 _T("\t enumerates the status for types of services.\n")
29 _T("\t queryex : Queries the extended status for a service, or\n")
30 _T("\t enumerates the status for types of services.\n")
31 _T("\t start : Starts a service.\n")
32 _T("\t pause : Sends a PAUSE control request to a service.\n")
33 _T("\t interrogate : Sends a INTERROGATE control request to a service.\n")
34 _T("\t continue : Sends a CONTINUE control request to a service.\n")
35 _T("\t stop : Sends a STOP request to a service.\n")
36 _T("\t config : Changes the configuration of a service (persistent).\n")
37 _T("\t description : Changes the description of a service.\n")
38 _T("\t failure : Changes the actions taken by a service upon failure.\n")
39 _T("\t qc : Queries the configuration information for a service.\n")
40 _T("\t qdescription : Queries the description for a service.\n")
41 _T("\t qfailure : Queries the actions taken by a service upon failure.\n")
42 _T("\t delete : Deletes a service (from the registry).\n")
43 _T("\t create : Creates a service (adds it to the registry).\n")
44 _T("\t control : Sends a control to a service.\n")
45 _T("\t sdshow : Displays a service's security descriptor.\n")
46 _T("\t sdset : Sets a service's security descriptor.\n")
47 _T("\t GetDisplayName : Gets the DisplayName for a service.\n")
48 _T("\t GetKeyName : Gets the ServiceKeyName for a service.\n")
49 _T("\t EnumDepend : Enumerates Service Dependencies.\n"));
50// "\n")
51// "\tService Name Independent Commands:\n")
52// "\t boot : (ok | bad) Indicates whether the last boot should\n")
53// "\t be saved as the last-known-good boot configuration\n")
54// "\t Lock : Locks the SCM Database\n")
55// "\t QueryLock : Queries the LockStatus for the SCM Database\n")
56
57 _tprintf(_T("\nWould you like to see help for the QUERY and QUERYEX commands? [ y | n ]: "));
58 c = _getch(); // _gettch isn't defined in our tchar.h
59 _tprintf(_T("%c\n"), c);
60 if (tolower(c) == 'y')
61 {
62 _tprintf(_T("QUERY and QUERYEX OPTIONS :\n")
63 _T(" If the query command is followed by a service name, the status\n")
64 _T(" for that service is returned. Further options do not apply in\n")
65 _T(" this case. If the query command is followed by nothing or one of\n")
66 _T(" the options listed below, the services are enumerated.\n")
67 _T(" type= Type of services to enumerate (driver, service, interact, all)\n")
68 _T(" (default = service)\n")
69 _T(" state= State of services to enumerate (active, all, inactive)\n")
70 _T(" (default = active)\n")
71 _T(" bufsize= The size (in bytes) of the enumeration buffer\n")
72 _T(" (default = 4096)\n")
73 _T(" ri= The resume index number at which to begin the enumeration\n")
74 _T(" (default = 0)\n")
75 _T(" group= Service group to enumerate\n")
76 _T(" (default = all groups)\n")
77 _T("SYNTAX EXAMPLES\n")
78 _T("sc query - Enumerates status for active services & drivers\n")
79 _T("sc query messenger - Displays status for the messenger service\n")
80 _T("sc queryex messenger - Displays extended status for the messenger service\n")
81 _T("sc query type= driver - Enumerates only active drivers\n")
82 _T("sc query type= service - Enumerates only Win32 services\n")
83 _T("sc query state= all - Enumerates all services & drivers\n")
84 _T("sc query bufsize= 50 - Enumerates with a 50 byte buffer.\n")
85 _T("sc query ri= 14 - Enumerates with resume index = 14\n")
86 _T("sc queryex group= \"\" - Enumerates active services not in a group\n")
87 _T("sc query type= service type= interact - Enumerates all interactive services\n")
88 _T("sc query type= driver group= NDIS - Enumerates all NDIS drivers\n"));
89 }
90}
int tolower(int c)
Definition: utclib.c:902
const GLubyte * c
Definition: glext.h:8905
#define c
Definition: ke_i.h:80
int _getch()
Definition: getch.c:16

Referenced by _tmain(), and ScControl().

◆ ParseCreateConfigArguments()

BOOL ParseCreateConfigArguments ( LPCTSTR ServiceArgs,
INT  ArgCount,
BOOL  bChangeService,
OUT LPSERVICE_CREATE_INFO  lpServiceInfo 
)

Definition at line 53 of file misc.c.

58{
59 INT i, ArgIndex = 1;
60
61 if (ArgCount < 1)
62 return FALSE;
63
64 ZeroMemory(lpServiceInfo, sizeof(SERVICE_CREATE_INFO));
65
66 if (bChangeService)
67 {
68 lpServiceInfo->dwServiceType = SERVICE_NO_CHANGE;
69 lpServiceInfo->dwStartType = SERVICE_NO_CHANGE;
70 lpServiceInfo->dwErrorControl = SERVICE_NO_CHANGE;
71 }
72
73 lpServiceInfo->lpServiceName = ServiceArgs[0];
74
75 ArgCount--;
76
77 while (ArgCount > 1)
78 {
79 if (!lstrcmpi(ServiceArgs[ArgIndex], _T("type=")))
80 {
81 for (i = 0; i < sizeof(TypeOpts) / sizeof(TypeOpts[0]); i++)
82 if (!lstrcmpi(ServiceArgs[ArgIndex + 1], TypeOpts[i].lpOption))
83 {
84 if (lpServiceInfo->dwServiceType == SERVICE_NO_CHANGE)
85 lpServiceInfo->dwServiceType = TypeOpts[i].dwValue;
86 else
87 lpServiceInfo->dwServiceType |= TypeOpts[i].dwValue;
88 break;
89 }
90
91 if (i == sizeof(TypeOpts) / sizeof(TypeOpts[0]))
92 break;
93 }
94 else if (!lstrcmpi(ServiceArgs[ArgIndex], _T("start=")))
95 {
96 for (i = 0; i < sizeof(StartOpts) / sizeof(StartOpts[0]); i++)
97 if (!lstrcmpi(ServiceArgs[ArgIndex + 1], StartOpts[i].lpOption))
98 {
99 lpServiceInfo->dwStartType = StartOpts[i].dwValue;
100 break;
101 }
102
103 if (i == sizeof(StartOpts) / sizeof(StartOpts[0]))
104 break;
105 }
106 else if (!lstrcmpi(ServiceArgs[ArgIndex], _T("error=")))
107 {
108 for (i = 0; i < sizeof(ErrorOpts) / sizeof(ErrorOpts[0]); i++)
109 if (!lstrcmpi(ServiceArgs[ArgIndex + 1], ErrorOpts[i].lpOption))
110 {
111 lpServiceInfo->dwErrorControl = ErrorOpts[i].dwValue;
112 break;
113 }
114
115 if (i == sizeof(ErrorOpts) / sizeof(ErrorOpts[0]))
116 break;
117 }
118 else if (!lstrcmpi(ServiceArgs[ArgIndex], _T("tag=")))
119 {
120 for (i = 0; i < sizeof(TagOpts) / sizeof(TagOpts[0]); i++)
121 if (!lstrcmpi(ServiceArgs[ArgIndex + 1], TagOpts[i].lpOption))
122 {
123 lpServiceInfo->bTagId = TagOpts[i].dwValue;
124 break;
125 }
126
127 if (i == sizeof(TagOpts) / sizeof(TagOpts[0]))
128 break;
129 }
130 else if (!lstrcmpi(ServiceArgs[ArgIndex], _T("binpath=")))
131 {
132 lpServiceInfo->lpBinaryPathName = ServiceArgs[ArgIndex + 1];
133 }
134 else if (!lstrcmpi(ServiceArgs[ArgIndex], _T("group=")))
135 {
136 lpServiceInfo->lpLoadOrderGroup = ServiceArgs[ArgIndex + 1];
137 }
138 else if (!lstrcmpi(ServiceArgs[ArgIndex], _T("depend=")))
139 {
140 lpServiceInfo->lpDependencies = ServiceArgs[ArgIndex + 1];
141 }
142 else if (!lstrcmpi(ServiceArgs[ArgIndex], _T("obj=")))
143 {
144 lpServiceInfo->lpServiceStartName = ServiceArgs[ArgIndex + 1];
145 }
146 else if (!lstrcmpi(ServiceArgs[ArgIndex], _T("displayname=")))
147 {
148 lpServiceInfo->lpDisplayName = ServiceArgs[ArgIndex + 1];
149 }
150 else if (!lstrcmpi(ServiceArgs[ArgIndex], _T("password=")))
151 {
152 lpServiceInfo->lpPassword = ServiceArgs[ArgIndex + 1];
153 }
154
155 ArgIndex += 2;
156 ArgCount -= 2;
157 }
158
159 return (ArgCount == 0);
160}
static const OPTION_INFO TagOpts[]
Definition: misc.c:45
static const OPTION_INFO TypeOpts[]
Definition: misc.c:18
static const OPTION_INFO ErrorOpts[]
Definition: misc.c:37
static const OPTION_INFO StartOpts[]
Definition: misc.c:28
DWORD dwValue
Definition: misc.c:15
#define ZeroMemory
Definition: winbase.h:1737
#define lstrcmpi
Definition: winbase.h:3898
#define SERVICE_NO_CHANGE
Definition: winsvc.h:20

Referenced by Create(), and SetConfig().

◆ ParseFailureArguments()

BOOL ParseFailureArguments ( LPCTSTR ServiceArgs,
INT  ArgCount,
OUT LPCTSTR ppServiceName,
OUT LPSERVICE_FAILURE_ACTIONS  pFailureActions 
)

◆ PauseUsage()

VOID PauseUsage ( VOID  )

Definition at line 102 of file usage.c.

103{
104 _tprintf(_T("DESCRIPTION:\n")
105 _T(" Sends a PAUSE control request to a service.\n")
106 _T("USAGE:\n")
107 _T(" sc <server> pause [service name]\n"));
108}

Referenced by ScControl().

◆ PrintService()

VOID PrintService ( LPCTSTR  ServiceName,
LPCTSTR  DisplayName,
LPSERVICE_STATUS_PROCESS  pStatus,
BOOL  bExtended 
)

Definition at line 13 of file print.c.

17{
18 _tprintf(_T("SERVICE_NAME: %s\n"), lpServiceName);
19
20 if (lpDisplayName)
21 _tprintf(_T("DISPLAY_NAME: %s\n"), lpDisplayName);
22
23 // Re-use PrintServiceStatus(), as SERVICE_STATUS_PROCESS is in fact an extension of SERVICE_STATUS.
25
26 if (bExtended)
27 {
28 _tprintf(_T("\tPID : %lu\n"),
29 pStatus->dwProcessId);
30 _tprintf(_T("\tFLAGS : %lu\n"),
31 pStatus->dwServiceFlags);
32 }
33
34 _tprintf(_T("\n"));
35}
__in WDFDMATRANSACTION __out NTSTATUS * pStatus

Referenced by Control(), Query(), and Start().

◆ PrintServiceStatus()

VOID PrintServiceStatus ( LPSERVICE_STATUS  pStatus)

Definition at line 39 of file print.c.

41{
42 _tprintf(_T("\tTYPE : %x "),
43 (unsigned int)pStatus->dwServiceType);
44
45 switch (pStatus->dwServiceType)
46 {
48 _tprintf(_T("KERNEL_DRIVER\n"));
49 break;
51 _tprintf(_T("FILE_SYSTEM_DRIVER\n"));
52 break;
54 _tprintf(_T("WIN32_OWN_PROCESS\n"));
55 break;
57 _tprintf(_T("WIN32_SHARE_PROCESS\n"));
58 break;
60 _tprintf(_T("WIN32_OWN_PROCESS (interactive)\n"));
61 break;
63 _tprintf(_T("WIN32_SHARE_PROCESS (interactive)\n"));
64 break;
65 default:
66 _tprintf(_T("\n"));
67 }
68
69 _tprintf(_T("\tSTATE : %x "),
70 (unsigned int)pStatus->dwCurrentState);
71
72 switch (pStatus->dwCurrentState)
73 {
74 case SERVICE_STOPPED:
75 _tprintf(_T("STOPPED\n"));
76 break;
78 _tprintf(_T("START_PENDING\n"));
79 break;
81 _tprintf(_T("STOP_PENDING\n"));
82 break;
83 case SERVICE_RUNNING:
84 _tprintf(_T("RUNNING\n"));
85 break;
87 _tprintf(_T("CONTINUE_PENDING\n"));
88 break;
90 _tprintf(_T("PAUSE_PENDING\n"));
91 break;
92 case SERVICE_PAUSED:
93 _tprintf(_T("PAUSED\n"));
94 break;
95 default:
96 _tprintf(_T("\n"));
97 }
98
99 _tprintf(_T("\t\t\t\t("));
100
101 if (pStatus->dwControlsAccepted & SERVICE_ACCEPT_STOP)
102 _tprintf(_T("STOPPABLE,"));
103 else
104 _tprintf(_T("NOT_STOPPABLE,"));
105
106 if (pStatus->dwControlsAccepted & SERVICE_ACCEPT_PAUSE_CONTINUE)
107 _tprintf(_T("PAUSABLE,"));
108 else
109 _tprintf(_T("NOT_PAUSABLE,"));
110
111 if (pStatus->dwControlsAccepted & SERVICE_ACCEPT_SHUTDOWN)
112 _tprintf(_T("ACCEPTS_SHUTDOWN"));
113 else
114 _tprintf(_T("IGNORES_SHUTDOWN"));
115
116 _tprintf(_T(")\n"));
117
118 _tprintf(_T("\tWIN32_EXIT_CODE : %u (0x%x)\n"),
119 (unsigned int)pStatus->dwWin32ExitCode,
120 (unsigned int)pStatus->dwWin32ExitCode);
121 _tprintf(_T("\tSERVICE_EXIT_CODE : %u (0x%x)\n"),
122 (unsigned int)pStatus->dwServiceSpecificExitCode,
123 (unsigned int)pStatus->dwServiceSpecificExitCode);
124 _tprintf(_T("\tCHECKPOINT : 0x%x\n"),
125 (unsigned int)pStatus->dwCheckPoint);
126 _tprintf(_T("\tWAIT_HINT : 0x%x\n"),
127 (unsigned int)pStatus->dwWaitHint);
128}
#define SERVICE_STOPPED
Definition: winsvc.h:21
#define SERVICE_ACCEPT_STOP
Definition: winsvc.h:28
#define SERVICE_STOP_PENDING
Definition: winsvc.h:23
#define SERVICE_PAUSED
Definition: winsvc.h:27
#define SERVICE_START_PENDING
Definition: winsvc.h:22
#define SERVICE_RUNNING
Definition: winsvc.h:24
#define SERVICE_ACCEPT_PAUSE_CONTINUE
Definition: winsvc.h:29
#define SERVICE_ACCEPT_SHUTDOWN
Definition: winsvc.h:30
#define SERVICE_PAUSE_PENDING
Definition: winsvc.h:26
#define SERVICE_CONTINUE_PENDING
Definition: winsvc.h:25
#define SERVICE_KERNEL_DRIVER
Definition: cmtypes.h:953
#define SERVICE_WIN32_SHARE_PROCESS
Definition: cmtypes.h:963
#define SERVICE_INTERACTIVE_PROCESS
Definition: cmtypes.h:967
#define SERVICE_FILE_SYSTEM_DRIVER
Definition: cmtypes.h:954

Referenced by EnumDepend(), and PrintService().

◆ Query()

BOOL Query ( LPCTSTR ServiceArgs,
DWORD  ArgCount,
BOOL  bExtended 
)

Definition at line 292 of file query.c.

295{
296 LPENUM_SERVICE_STATUS_PROCESS pServiceStatus = NULL;
297 DWORD NumServices = 0;
298 DWORD dwServiceType = SERVICE_WIN32;
299 DWORD dwServiceState = SERVICE_ACTIVE;
300 DWORD dwBufferSize = 0;
301 DWORD dwResumeIndex = 0;
302 LPCTSTR pszGroupName = NULL;
303 LPCTSTR pszServiceName = NULL;
304 DWORD i;
305
306#ifdef SCDBG
307 LPCTSTR *TmpArgs = ServiceArgs;
308 INT TmpCnt = ArgCount;
309
310 _tprintf(_T("Arguments:\n"));
311 while (TmpCnt)
312 {
313 _tprintf(_T(" %s\n"), *TmpArgs);
314 TmpArgs++;
315 TmpCnt--;
316 }
317 _tprintf(_T("\n"));
318#endif /* SCDBG */
319
320 /* Parse arguments */
321 if (!ParseQueryArguments(ServiceArgs,
322 ArgCount,
323 &dwServiceType,
324 &dwServiceState,
325 &dwBufferSize,
326 &dwResumeIndex,
327 &pszGroupName,
328 &pszServiceName))
329 return FALSE;
330
331#ifdef SCDBG
332 _tprintf(_T("Service type: %lx\n"), dwServiceType);
333 _tprintf(_T("Service state: %lx\n"), dwServiceState);
334 _tprintf(_T("Buffer size: %lu\n"), dwBufferSize);
335 _tprintf(_T("Resume index: %lu\n"), dwResumeIndex);
336 _tprintf(_T("Group name: %s\n"), pszGroupName);
337 _tprintf(_T("Service name: %s\n"), pszServiceName);
338#endif
339
340 if (pszServiceName)
341 {
342 /* Print only the requested service */
343
345
346 pStatus = QueryService(pszServiceName);
347 if (pStatus)
348 {
349 PrintService(pszServiceName,
350 NULL,
351 pStatus,
352 bExtended);
353
355 }
356 }
357 else
358 {
359 /* Print all matching services */
360
361 NumServices = EnumServices(&pServiceStatus,
362 dwServiceType,
363 dwServiceState,
364 dwBufferSize,
365 dwResumeIndex,
366 pszGroupName);
367 if (NumServices == 0)
368 return FALSE;
369
370 for (i = 0; i < NumServices; i++)
371 {
372 PrintService(pServiceStatus[i].lpServiceName,
373 pServiceStatus[i].lpDisplayName,
374 &pServiceStatus[i].ServiceStatusProcess,
375 bExtended);
376 }
377
378#ifdef SCDBG
379 _tprintf(_T("number : %lu\n"), NumServices);
380#endif
381
382 if (pServiceStatus)
383 HeapFree(GetProcessHeap(), 0, pServiceStatus);
384 }
385
386 return TRUE;
387}
LPSERVICE_STATUS_PROCESS QueryService(LPCTSTR ServiceName)
Definition: query.c:13
static BOOL ParseQueryArguments(IN LPCTSTR *ServiceArgs, IN INT ArgCount, OUT PDWORD pdwServiceType, OUT PDWORD pdwServiceState, OUT PDWORD pdwBufferSize, OUT PDWORD pdwResumeIndex, OUT LPCTSTR *ppszGroupName, OUT LPCTSTR *ppszServiceName)
Definition: query.c:152
static DWORD EnumServices(ENUM_SERVICE_STATUS_PROCESS **pServiceStatus, DWORD dwServiceType, DWORD dwServiceState, DWORD dwBufferSize, DWORD dwResumeIndex, LPCTSTR pszGroupName)
Definition: query.c:75
#define SERVICE_ACTIVE
Definition: winsvc.h:50
#define SERVICE_WIN32
Definition: cmtypes.h:964

Referenced by BasepGetComputerNameFromNtPath(), IopQueryBusDescription(), IopQueryDeviceDescription(), IoQueryDeviceDescription(), NtQueryInformationProcess(), NtQuerySystemInformation(), PrintDiskData(), ScControl(), SHELL_IncludeItemInFolderEnum(), StorPortInitializePerfOpts(), Test_ApphelpCheckRunApp(), WSALookupServiceBeginW(), WSALookupServiceEnd(), WSALookupServiceNextW(), WsNqAddProvider(), WsNqDereference(), WsNqInitialize(), WsNqNextProvider(), WsNqPreviousProvider(), and WsNqValidateAndReference().

◆ QueryConfig()

BOOL QueryConfig ( LPCTSTR  ServiceName)

Definition at line 12 of file config.c.

13{
14 SC_HANDLE hManager = NULL;
15 SC_HANDLE hService = NULL;
16 BOOL bResult = TRUE;
17 DWORD cbBytesNeeded = 0;
18 LPQUERY_SERVICE_CONFIG pServiceConfig = NULL;
19 LPWSTR lpPtr;
20 SSIZE_T nLen, i;
21
22#ifdef SCDBG
23 _tprintf(_T("service to show configuration - %s\n\n"), ServiceName);
24#endif
25
26 hManager = OpenSCManager(NULL,
27 NULL,
29 if (hManager == NULL)
30 {
31 _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
32 bResult = FALSE;
33 goto done;
34 }
35
36 hService = OpenService(hManager, ServiceName, SERVICE_QUERY_CONFIG);
37 if (hService == NULL)
38 {
39 _tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError());
40 bResult = FALSE;
41 goto done;
42 }
43
44 if (!QueryServiceConfig(hService,
45 NULL,
46 0,
47 &cbBytesNeeded))
48 {
49 if (cbBytesNeeded == 0)
50 {
51 _tprintf(_T("[SC] QueryServiceConfig FAILED %lu:\n\n"), GetLastError());
52 bResult = FALSE;
53 goto done;
54 }
55 }
56
57 pServiceConfig = HeapAlloc(GetProcessHeap(), 0, cbBytesNeeded);
58 if (pServiceConfig == NULL)
59 {
61 _tprintf(_T("[SC] HeapAlloc FAILED %lu:\n\n"), GetLastError());
62 bResult = FALSE;
63 goto done;
64 }
65
66 if (!QueryServiceConfig(hService,
67 pServiceConfig,
68 cbBytesNeeded,
69 &cbBytesNeeded))
70 {
71 _tprintf(_T("[SC] QueryServiceConfig FAILED %lu:\n\n"), GetLastError());
72 bResult = FALSE;
73 goto done;
74 }
75
76 _tprintf(_T("[SC] QueryServiceConfig SUCCESS\n\n"));
77
78 _tprintf(_T("SERVICE_NAME: %s\n"), ServiceName);
79 _tprintf(_T(" TYPE : %-3lx "), pServiceConfig->dwServiceType);
80 switch (pServiceConfig->dwServiceType)
81 {
83 _tprintf(_T("KERNEL_DRIVER\n"));
84 break;
85
87 _tprintf(_T("FILE_SYSTEM_DRIVER\n"));
88 break;
89
91 _tprintf(_T("WIN32_OWN_PROCESS\n"));
92 break;
93
95 _tprintf(_T("WIN32_SHARE_PROCESS\n"));
96 break;
97
99 _tprintf(_T("WIN32_OWN_PROCESS (interactive)\n"));
100 break;
101
103 _tprintf(_T("WIN32_SHARE_PROCESS (interactive)\n"));
104 break;
105
106 default:
107 _tprintf(_T("\n"));
108 break;
109 }
110
111 _tprintf(_T(" START_TYPE : %-3lx "), pServiceConfig->dwStartType);
112 switch (pServiceConfig->dwStartType)
113 {
115 _tprintf(_T("BOOT_START\n"));
116 break;
117
119 _tprintf(_T("SYSTEM_START\n"));
120 break;
121
123 _tprintf(_T("AUTO_START\n"));
124 break;
125
127 _tprintf(_T("DEMAND_START\n"));
128 break;
129
130 case SERVICE_DISABLED:
131 _tprintf(_T("DISABLED\n"));
132 break;
133
134 default:
135 _tprintf(_T("\n"));
136 break;
137 }
138
139 _tprintf(_T(" ERROR_CONTROL : %-3lx "), pServiceConfig->dwErrorControl);
140 switch (pServiceConfig->dwErrorControl)
141 {
143 _tprintf(_T("IGNORE\n"));
144 break;
145
147 _tprintf(_T("NORMAL\n"));
148 break;
149
151 _tprintf(_T("SEVERE\n"));
152 break;
153
155 _tprintf(_T("CRITICAL\n"));
156 break;
157
158 default:
159 _tprintf(_T("\n"));
160 break;
161 }
162
163 _tprintf(_T(" BINARY_PATH_NAME : %s\n"), pServiceConfig->lpBinaryPathName);
164 _tprintf(_T(" LOAD_ORDER_GROUP : %s\n"), pServiceConfig->lpLoadOrderGroup);
165 _tprintf(_T(" TAG : %lu\n"), pServiceConfig->dwTagId);
166 _tprintf(_T(" DISPLAY_NAME : %s\n"), pServiceConfig->lpDisplayName);
167 _tprintf(_T(" DEPENDENCIES : "));
168 lpPtr = pServiceConfig->lpDependencies;
169 i = 0;
170 while (*lpPtr != _T('\0'))
171 {
172 nLen = _tcslen(lpPtr);
173 if (i != 0)
174 _tprintf(_T("\n : "));
175 _tprintf(_T("%s"), lpPtr);
176 lpPtr = lpPtr + nLen + 1;
177 i++;
178 }
179 _tprintf(_T("\n"));
180
181 _tprintf(_T(" SERVICE_START_NAME : %s\n"), pServiceConfig->lpServiceStartName);
182
183done:
184 if (bResult == FALSE)
186
187 if (pServiceConfig != NULL)
188 HeapFree(GetProcessHeap(), 0, pServiceConfig);
189
190 if (hService)
191 CloseServiceHandle(hService);
192
193 if (hManager)
194 CloseServiceHandle(hManager);
195
196 return bResult;
197}
LONG_PTR SSIZE_T
Definition: basetsd.h:181
LPSTR lpServiceStartName
Definition: winsvc.h:152
#define QueryServiceConfig
Definition: winsvc.h:580
#define SERVICE_QUERY_CONFIG
Definition: winsvc.h:53
#define SERVICE_ERROR_SEVERE
Definition: cmtypes.h:983
#define SERVICE_DISABLED
Definition: cmtypes.h:979
#define SERVICE_AUTO_START
Definition: cmtypes.h:977
#define SERVICE_BOOT_START
Definition: cmtypes.h:975
#define SERVICE_ERROR_CRITICAL
Definition: cmtypes.h:984
#define SERVICE_SYSTEM_START
Definition: cmtypes.h:976
#define SERVICE_ERROR_IGNORE
Definition: cmtypes.h:981
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define _tcslen
Definition: xmlstorage.h:198

Referenced by ScControl().

◆ QueryConfigUsage()

VOID QueryConfigUsage ( VOID  )

Definition at line 197 of file usage.c.

198{
199 _tprintf(_T("DESCRIPTION:\n")
200 _T(" Queries the configuration information for a service.\n")
201 _T("USAGE:\n")
202 _T(" sc <server> qc [service name] <bufferSize>\n"));
203}

Referenced by ScControl().

◆ QueryDescription()

BOOL QueryDescription ( LPCTSTR  ServiceName)

Definition at line 12 of file description.c.

13{
14 SC_HANDLE hManager = NULL;
15 SC_HANDLE hService = NULL;
16 BOOL bResult = TRUE;
17 DWORD cbBytesNeeded = 0;
18 LPSERVICE_DESCRIPTION pServiceDescription = NULL;
19
20#ifdef SCDBG
21 _tprintf(_T("service to show description - %s\n\n"), ServiceName);
22#endif
23
24 hManager = OpenSCManager(NULL,
25 NULL,
27 if (hManager == NULL)
28 {
29 _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
30 bResult = FALSE;
31 goto done;
32 }
33
34 hService = OpenService(hManager, ServiceName, SERVICE_QUERY_CONFIG);
35 if (hService == NULL)
36 {
37 _tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError());
38 bResult = FALSE;
39 goto done;
40 }
41
42 if (!QueryServiceConfig2(hService,
44 NULL,
45 0,
46 &cbBytesNeeded))
47 {
48 if (cbBytesNeeded == 0)
49 {
50 _tprintf(_T("[SC] QueryServiceConfig2 FAILED %lu:\n\n"), GetLastError());
51 bResult = FALSE;
52 goto done;
53 }
54 }
55
56 pServiceDescription = HeapAlloc(GetProcessHeap(), 0, cbBytesNeeded);
57 if (pServiceDescription == NULL)
58 {
60 _tprintf(_T("[SC] HeapAlloc FAILED %lu:\n\n"), GetLastError());
61 bResult = FALSE;
62 goto done;
63 }
64
65 if (!QueryServiceConfig2(hService,
67 (LPBYTE)pServiceDescription,
68 cbBytesNeeded,
69 &cbBytesNeeded))
70 {
71 _tprintf(_T("[SC] QueryServiceConfig2 FAILED %lu:\n\n"), GetLastError());
72 bResult = FALSE;
73 goto done;
74 }
75
76 _tprintf(_T("[SC] QueryServiceConfig2 SUCCESS\n\n"));
77
78 _tprintf(_T("SERVICE_NAME: %s\n"), ServiceName);
79 _tprintf(_T(" DESCRIPTION : %s\n"),
80 (pServiceDescription->lpDescription) ? pServiceDescription->lpDescription : _T(""));
81
82done:
83 if (bResult == FALSE)
85
86 if (pServiceDescription != NULL)
87 HeapFree(GetProcessHeap(), 0, pServiceDescription);
88
89 if (hService)
90 CloseServiceHandle(hService);
91
92 if (hManager)
93 CloseServiceHandle(hManager);
94
95 return bResult;
96}
unsigned char * LPBYTE
Definition: typedefs.h:53
#define SERVICE_CONFIG_DESCRIPTION
Definition: winsvc.h:65
#define QueryServiceConfig2
Definition: winsvc.h:581

Referenced by ScControl().

◆ QueryDescriptionUsage()

VOID QueryDescriptionUsage ( VOID  )

Definition at line 205 of file usage.c.

206{
207 _tprintf(_T("DESCRIPTION:\n")
208 _T(" Retrieves the description string of a service.\n")
209 _T("USAGE:\n")
210 _T(" sc <server> qdescription [service name] <bufferSize>\n"));
211}

Referenced by ScControl().

◆ QueryFailure()

BOOL QueryFailure ( LPCTSTR  ServiceName)

Definition at line 11 of file failure.c.

12{
13 SC_HANDLE hManager = NULL;
14 SC_HANDLE hService = NULL;
15 BOOL bResult = TRUE;
16 DWORD cbBytesNeeded = 0;
17 LPSERVICE_FAILURE_ACTIONS pServiceFailure = NULL;
18 INT i;
19
20#ifdef SCDBG
21 _tprintf(_T("service to show failure action - %s\n\n"), ServiceName);
22#endif
23
24 hManager = OpenSCManager(NULL,
25 NULL,
27 if (hManager == NULL)
28 {
29 bResult = FALSE;
30 goto done;
31 }
32
33 hService = OpenService(hManager, ServiceName, SERVICE_QUERY_CONFIG);
34 if (hService == NULL)
35 {
36 bResult = FALSE;
37 goto done;
38 }
39
40 if (!QueryServiceConfig2(hService,
42 NULL,
43 0,
44 &cbBytesNeeded))
45 {
46 if (cbBytesNeeded == 0)
47 {
48 bResult = FALSE;
49 goto done;
50 }
51 }
52
53 pServiceFailure = HeapAlloc(GetProcessHeap(), 0, cbBytesNeeded);
54 if (pServiceFailure == NULL)
55 {
57 bResult = FALSE;
58 goto done;
59 }
60
61 if (!QueryServiceConfig2(hService,
63 (LPBYTE)pServiceFailure,
64 cbBytesNeeded,
65 &cbBytesNeeded))
66 {
67 bResult = FALSE;
68 goto done;
69 }
70
71 _tprintf(_T("SERVICE_NAME: %s\n"), ServiceName);
72 _tprintf(_T(" RESET_PERIOD : %lu seconds\n"), pServiceFailure->dwResetPeriod);
73 _tprintf(_T(" REBOOT_MESSAGE : %s\n"), (pServiceFailure->lpRebootMsg) ? pServiceFailure->lpRebootMsg : _T(""));
74 _tprintf(_T(" COMMAND_LINE : %s\n"), (pServiceFailure->lpCommand) ? pServiceFailure->lpCommand : _T(""));
75 _tprintf(_T(" FAILURE_ACTIONS : "));
76 for (i = 0; i < pServiceFailure->cActions; i++)
77 {
78 if (i != 0)
79 _tprintf(_T(" "));
80 switch (pServiceFailure->lpsaActions[i].Type)
81 {
82 case SC_ACTION_NONE:
83 continue;
84
86 _tprintf(_T("RESTART -- Delay = %lu milliseconds.\n"), pServiceFailure->lpsaActions[i].Delay);
87 break;
88
90 _tprintf(_T("REBOOT -- Delay = %lu milliseconds.\n"), pServiceFailure->lpsaActions[i].Delay);
91 break;
92
94 _tprintf(_T("RUN_COMMAND -- Delay = %lu milliseconds.\n"), pServiceFailure->lpsaActions[i].Delay);
95 break;
96
97 default:
98 _tprintf(_T("\n"));
99 break;
100 }
101 }
102
103done:
104 if (bResult == FALSE)
106
107 if (pServiceFailure != NULL)
108 HeapFree(GetProcessHeap(), 0, pServiceFailure);
109
110 if (hService)
111 CloseServiceHandle(hService);
112
113 if (hManager)
114 CloseServiceHandle(hManager);
115
116 return bResult;
117}
@ SC_ACTION_RUN_COMMAND
Definition: winsvc.h:202
@ SC_ACTION_REBOOT
Definition: winsvc.h:201
@ SC_ACTION_RESTART
Definition: winsvc.h:200
@ SC_ACTION_NONE
Definition: winsvc.h:199
#define SERVICE_CONFIG_FAILURE_ACTIONS
Definition: winsvc.h:66

Referenced by ScControl().

◆ QueryFailureUsage()

VOID QueryFailureUsage ( VOID  )

Definition at line 213 of file usage.c.

214{
215 _tprintf(_T("DESCRIPTION:\n")
216 _T(" Retrieves the actions performed on service failure.\n")
217 _T("USAGE:\n")
218 _T(" sc <server> qfailure [service name] <bufferSize>\n"));
219}

Referenced by ScControl().

◆ QueryService()

LPSERVICE_STATUS_PROCESS QueryService ( LPCTSTR  ServiceName)

Definition at line 13 of file query.c.

14{
15 SC_HANDLE hSCManager = NULL;
16 LPSERVICE_STATUS_PROCESS pServiceInfo = NULL;
17 SC_HANDLE hSc = NULL;
18 DWORD BufSiz = 0;
19 DWORD BytesNeeded = 0;
20 DWORD Ret;
21
23 NULL,
25 if (hSCManager == NULL)
26 {
28 return NULL;
29 }
30
34 if (hSc == NULL)
35 goto fail;
36
37 Ret = QueryServiceStatusEx(hSc,
39 NULL,
40 BufSiz,
41 &BytesNeeded);
42 if ((Ret != 0) || (GetLastError() != ERROR_INSUFFICIENT_BUFFER))
43 goto fail;
44
46 0,
47 BytesNeeded);
48 if (pServiceInfo == NULL)
49 goto fail;
50
51 if (!QueryServiceStatusEx(hSc,
53 (LPBYTE)pServiceInfo,
54 BytesNeeded,
55 &BytesNeeded))
56 {
57 goto fail;
58 }
59
62 return pServiceInfo;
63
64fail:
66 if (pServiceInfo) HeapFree(GetProcessHeap(), 0, pServiceInfo);
67 if (hSc) CloseServiceHandle(hSc);
69 return NULL;
70}
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
BOOL WINAPI QueryServiceStatusEx(SC_HANDLE hService, SC_STATUS_TYPE InfoLevel, LPBYTE lpBuffer, DWORD cbBufSize, LPDWORD pcbBytesNeeded)
Definition: scm.c:2887
#define SERVICE_QUERY_STATUS
Definition: winsvc.h:55
@ SC_STATUS_PROCESS_INFO
Definition: winsvc.h:119
struct _SERVICE_STATUS_PROCESS * LPSERVICE_STATUS_PROCESS

Referenced by Query(), and Start().

◆ ReportLastError()

VOID ReportLastError ( VOID  )

Definition at line 15 of file sc.c.

16{
17 LPVOID lpMsgBuf;
18 DWORD RetVal;
19
22 {
26 NULL,
28 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
29 (LPTSTR) &lpMsgBuf,
30 0,
31 NULL );
32
33 if (RetVal != 0)
34 {
35 _tprintf(_T("%s"), (LPTSTR)lpMsgBuf);
36 LocalFree(lpMsgBuf);
37 }
38 }
39}
#define ERROR_SUCCESS
Definition: deptool.c:10
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define LANG_NEUTRAL
Definition: nls.h:22
#define MAKELANGID(p, s)
Definition: nls.h:15
#define SUBLANG_DEFAULT
Definition: nls.h:168
#define FormatMessage
Definition: winbase.h:3820
#define FORMAT_MESSAGE_IGNORE_INSERTS
Definition: winbase.h:446
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:449
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:445

◆ SdSet()

BOOL SdSet ( LPCTSTR  ServiceName,
LPCTSTR  SecurityDescriptor 
)

Definition at line 12 of file sdset.c.

13{
14 SC_HANDLE hManager = NULL;
15 SC_HANDLE hService = NULL;
16 BOOL bResult = TRUE;
17 ULONG ulSecurityDescriptorSize = 0;
18 PSECURITY_DESCRIPTOR pSecurityDescriptor = NULL;
19
20#ifdef SCDBG
21 _tprintf(_T("service to set sd - %s\n\n"), ServiceName);
22#endif
23
24 hManager = OpenSCManager(NULL,
25 NULL,
27 if (hManager == NULL)
28 {
29 _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
30 bResult = FALSE;
31 goto done;
32 }
33
34 hService = OpenService(hManager, ServiceName, WRITE_DAC);
35 if (hService == NULL)
36 {
37 _tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError());
38 bResult = FALSE;
39 goto done;
40 }
41
42 if (!ConvertStringSecurityDescriptorToSecurityDescriptor(StringSecurityDescriptor,
44 &pSecurityDescriptor,
45 &ulSecurityDescriptorSize))
46 {
47 _tprintf(_T("[SC] ConvertStringSecurityDescriptorToSecurityDescriptor FAILED %lu:\n\n"), GetLastError());
48 bResult = FALSE;
49 goto done;
50 }
51
52 if (!SetServiceObjectSecurity(hService,
54 pSecurityDescriptor))
55 {
56 _tprintf(_T("[SC] SetServiceObjectSecurity FAILED %lu:\n\n"), GetLastError());
57 bResult = FALSE;
58 goto done;
59 }
60
61done:
62 if (bResult == FALSE)
64
65 if (pSecurityDescriptor != NULL)
66 LocalFree(pSecurityDescriptor);
67
68 if (hService)
69 CloseServiceHandle(hService);
70
71 if (hManager)
72 CloseServiceHandle(hManager);
73
74 return bResult;
75}
#define WRITE_DAC
Definition: nt_native.h:59
BOOL WINAPI SetServiceObjectSecurity(SC_HANDLE hService, SECURITY_INFORMATION dwSecurityInformation, PSECURITY_DESCRIPTOR lpSecurityDescriptor)
Definition: scm.c:2774
#define ConvertStringSecurityDescriptorToSecurityDescriptor
Definition: sddl.h:162
#define SDDL_REVISION_1
Definition: sddl.h:30
uint32_t ULONG
Definition: typedefs.h:59
#define DACL_SECURITY_INFORMATION
Definition: setypes.h:125

Referenced by ScControl().

◆ SdSetUsage()

VOID SdSetUsage ( VOID  )

Definition at line 189 of file usage.c.

190{
191 _tprintf(_T("DESCRIPTION:\n")
192 _T(" Sets a service's security descriptor.\n")
193 _T("USAGE:\n")
194 _T(" sc <server> sdset <service name> <SD in SDDL format>\n"));
195}

Referenced by ScControl().

◆ SdShow()

BOOL SdShow ( LPCTSTR  ServiceName)

Definition at line 12 of file sdshow.c.

13{
14 SC_HANDLE hManager = NULL;
15 SC_HANDLE hService = NULL;
16 BOOL bResult = TRUE;
17 DWORD cbBytesNeeded = 0;
18 PSECURITY_DESCRIPTOR pSecurityDescriptor = NULL;
19 LPTSTR pStringBuffer = NULL;
20
21#ifdef SCDBG
22 _tprintf(_T("service to show sd - %s\n\n"), ServiceName);
23#endif
24
25 hManager = OpenSCManager(NULL,
26 NULL,
28 if (hManager == NULL)
29 {
30 _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
31 bResult = FALSE;
32 goto done;
33 }
34
35 hService = OpenService(hManager, ServiceName, READ_CONTROL);
36 if (hService == NULL)
37 {
38 _tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError());
39 bResult = FALSE;
40 goto done;
41 }
42
43 if (!QueryServiceObjectSecurity(hService,
45 (PSECURITY_DESCRIPTOR)&pSecurityDescriptor,
47 &cbBytesNeeded))
48 {
49 if (cbBytesNeeded == 0)
50 {
51 _tprintf(_T("[SC] QueryServiceObjectSecurity FAILED %lu:\n\n"), GetLastError());
52 bResult = FALSE;
53 goto done;
54 }
55 }
56
57 pSecurityDescriptor = HeapAlloc(GetProcessHeap(), 0, cbBytesNeeded);
58 if (pSecurityDescriptor == NULL)
59 {
61 _tprintf(_T("[SC] HeapAlloc FAILED %lu:\n\n"), GetLastError());
62 bResult = FALSE;
63 goto done;
64 }
65
66 if (!QueryServiceObjectSecurity(hService,
68 pSecurityDescriptor,
69 cbBytesNeeded,
70 &cbBytesNeeded))
71 {
72 _tprintf(_T("[SC] QueryServiceObjectSecurity FAILED %lu:\n\n"), GetLastError());
73 bResult = FALSE;
74 goto done;
75 }
76
80 &pStringBuffer,
81 NULL))
82 {
83 _tprintf(_T("[SC] ConvertSecurityDescriptorToStringSecurityDescriptor FAILED %lu:\n\n"), GetLastError());
84 bResult = FALSE;
85 goto done;
86 }
87
88 _tprintf(_T("\n%s\n"), pStringBuffer);
89
90done:
91 if (bResult == FALSE)
93
94 if (pStringBuffer != NULL)
95 LocalFree(pStringBuffer);
96
97 if (pSecurityDescriptor != NULL)
98 HeapFree(GetProcessHeap(), 0, pSecurityDescriptor);
99
100 if (hService)
101 CloseServiceHandle(hService);
102
103 if (hManager)
104 CloseServiceHandle(hManager);
105
106 return bResult;
107}
#define READ_CONTROL
Definition: nt_native.h:58
BOOL WINAPI QueryServiceObjectSecurity(SC_HANDLE hService, SECURITY_INFORMATION dwSecurityInformation, PSECURITY_DESCRIPTOR lpSecurityDescriptor, DWORD cbBufSize, LPDWORD pcbBytesNeeded)
Definition: scm.c:2732
#define ConvertSecurityDescriptorToStringSecurityDescriptor
Definition: sddl.h:164

Referenced by ScControl().

◆ SdShowUsage()

VOID SdShowUsage ( VOID  )

Definition at line 181 of file usage.c.

182{
183 _tprintf(_T("DESCRIPTION:\n")
184 _T(" Displays a service's security descriptor in SDDL format.\n")
185 _T("USAGE:\n")
186 _T(" sc <server> sdshow <service name>\n"));
187}

Referenced by ScControl().

◆ SetConfig()

BOOL SetConfig ( LPCTSTR ServiceArgs,
INT  ArgCount 
)

Definition at line 199 of file config.c.

200{
201 SC_HANDLE hManager = NULL;
202 SC_HANDLE hService = NULL;
203 BOOL bResult = TRUE;
205
206 if (!ParseCreateConfigArguments(ServiceArgs, ArgCount, TRUE, &ServiceInfo))
207 {
209 return FALSE;
210 }
211
212#ifdef SCDBG
213 _tprintf(_T("service name - %s\n"), ServiceInfo.lpServiceName);
214 _tprintf(_T("display name - %s\n"), ServiceInfo.lpDisplayName);
215 _tprintf(_T("service type - %lu\n"), ServiceInfo.dwServiceType);
216 _tprintf(_T("start type - %lu\n"), ServiceInfo.dwStartType);
217 _tprintf(_T("error control - %lu\n"), ServiceInfo.dwErrorControl);
218 _tprintf(_T("Binary path - %s\n"), ServiceInfo.lpBinaryPathName);
219 _tprintf(_T("load order group - %s\n"), ServiceInfo.lpLoadOrderGroup);
220 _tprintf(_T("tag - %lu\n"), ServiceInfo.dwTagId);
221 _tprintf(_T("dependencies - %s\n"), ServiceInfo.lpDependencies);
222 _tprintf(_T("account start name - %s\n"), ServiceInfo.lpServiceStartName);
223 _tprintf(_T("account password - %s\n"), ServiceInfo.lpPassword);
224#endif
225
226 hManager = OpenSCManager(NULL,
227 NULL,
229 if (hManager == NULL)
230 {
231 _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
232 bResult = FALSE;
233 goto done;
234 }
235
236 hService = OpenService(hManager,
237 ServiceInfo.lpServiceName,
239 if (hService == NULL)
240 {
241 _tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError());
242 bResult = FALSE;
243 goto done;
244 }
245
246 if (!ChangeServiceConfig(hService,
247 ServiceInfo.dwServiceType,
248 ServiceInfo.dwStartType,
249 ServiceInfo.dwErrorControl,
250 ServiceInfo.lpBinaryPathName,
251 ServiceInfo.lpLoadOrderGroup,
252 ServiceInfo.bTagId ? &ServiceInfo.dwTagId : NULL,
253 ServiceInfo.lpDependencies,
254 ServiceInfo.lpServiceStartName,
255 ServiceInfo.lpPassword,
256 ServiceInfo.lpDisplayName))
257 {
258 _tprintf(_T("[SC] ChangeServiceConfig FAILED %lu:\n\n"), GetLastError());
259 bResult = FALSE;
260 goto done;
261 }
262
263 _tprintf(_T("[SC] ChangeServiceConfig SUCCESS\n\n"));
264
265done:
266 if (bResult == FALSE)
268
269 if (hService)
270 CloseServiceHandle(hService);
271
272 if (hManager)
273 CloseServiceHandle(hManager);
274
275 return bResult;
276}
VOID SetConfigUsage(VOID)
Definition: usage.c:229
#define SERVICE_CHANGE_CONFIG
Definition: winsvc.h:54
#define ChangeServiceConfig
Definition: winsvc.h:567

Referenced by DECLARE_INTERFACE_(), and ScControl().

◆ SetConfigUsage()

VOID SetConfigUsage ( VOID  )

Definition at line 229 of file usage.c.

230{
231 _tprintf(_T("DESCRIPTION:\n")
232 _T(" Modifies a service entry in the registry and Service Database.\n")
233 _T("USAGE:\n")
234 _T(" sc <server> config [service name] <option1> <option2>...\n")
235 _T("CONFIG OPTIONS:\n")
236 _T(" NOTE: The option name includes the equal sign.\n")
237 _T(" type= <own|share|interact|kernel|filesys|rec>\n")
238 _T(" start= <boot|system|auto|demand|disabled>\n")
239 _T(" error= <normal|severe|critical|ignore>\n")
240 _T(" binPath= <BinaryPathName>\n")
241 _T(" group= <LoadOrderGroup>\n")
242 _T(" tag= <yes|no>\n")
243 _T(" depend= <Dependencies(separated by / (forward slash))>\n")
244 _T(" obj= <AccountName|ObjectName>\n")
245 _T(" DisplayName= <display name>\n")
246 _T(" password= <password>\n"));
247}

Referenced by SetConfig().

◆ SetDescription()

BOOL SetDescription ( LPCTSTR  ServiceName,
LPCTSTR  Description 
)

Definition at line 99 of file description.c.

100{
101 SC_HANDLE hManager = NULL;
102 SC_HANDLE hService = NULL;
103 BOOL bResult = TRUE;
104 SERVICE_DESCRIPTION ServiceDescription;
105
106#ifdef SCDBG
107 _tprintf(_T("service to set description - %s\n\n"), ServiceName);
108#endif
109
110 hManager = OpenSCManager(NULL,
111 NULL,
113 if (hManager == NULL)
114 {
115 _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
116 bResult = FALSE;
117 goto done;
118 }
119
120 hService = OpenService(hManager, ServiceName, SERVICE_CHANGE_CONFIG);
121 if (hService == NULL)
122 {
123 _tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError());
124 bResult = FALSE;
125 goto done;
126 }
127
128 ServiceDescription.lpDescription = (LPTSTR)Description;
129
130 if (!ChangeServiceConfig2(hService,
132 (LPBYTE)&ServiceDescription))
133 {
134 _tprintf(_T("[SC] ChangeServiceConfig2 FAILED %lu:\n\n"), GetLastError());
135 bResult = FALSE;
136 goto done;
137 }
138
139 _tprintf(_T("[SC] ChangeServiceConfig2 SUCCESS\n\n"));
140
141done:
142 if (bResult == FALSE)
144
145 if (hService)
146 CloseServiceHandle(hService);
147
148 if (hManager)
149 CloseServiceHandle(hManager);
150
151 return bResult;
152}
static const WCHAR Description[]
Definition: oid.c:1266
#define ChangeServiceConfig2
Definition: winsvc.h:568

Referenced by ScControl().

◆ SetDescriptionUsage()

VOID SetDescriptionUsage ( VOID  )

Definition at line 221 of file usage.c.

222{
223 _tprintf(_T("DESCRIPTION:\n")
224 _T(" Sets the description string of a service.\n")
225 _T("USAGE:\n")
226 _T(" sc <server> description [service name] [description]\n"));
227}

Referenced by ScControl().

◆ SetFailure()

BOOL SetFailure ( LPCTSTR ServiceArgs,
INT  ArgCount 
)

Definition at line 120 of file failure.c.

123{
124 SC_HANDLE hManager = NULL;
125 SC_HANDLE hService = NULL;
126 BOOL bResult = TRUE;
127 SERVICE_FAILURE_ACTIONS FailureActions;
128 LPCTSTR lpServiceName = NULL;
129 BOOLEAN Old = FALSE;
130
131 ZeroMemory(&FailureActions, sizeof(SERVICE_FAILURE_ACTIONS));
132
133 if (!ParseFailureArguments(ServiceArgs, ArgCount, &lpServiceName, &FailureActions))
134 {
136 return FALSE;
137 }
138
139 hManager = OpenSCManager(NULL,
140 NULL,
142 if (hManager == NULL)
143 {
144 _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
145 bResult = FALSE;
146 goto done;
147 }
148
149 hService = OpenService(hManager,
150 lpServiceName,
152 if (hService == NULL)
153 {
154 _tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError());
155 bResult = FALSE;
156 goto done;
157 }
158
160
161 if (!ChangeServiceConfig2(hService,
163 (LPBYTE)&FailureActions))
164 {
165 _tprintf(_T("[SC] ChangeServiceConfig2 FAILED %lu:\n\n"), GetLastError());
166 bResult = FALSE;
167 goto done;
168 }
169
170 _tprintf(_T("[SC] ChangeServiceConfig2 SUCCESS\n\n"));
171
172done:
174
175 if (bResult == FALSE)
177
178 if (FailureActions.lpsaActions != NULL)
179 HeapFree(GetProcessHeap(), 0, FailureActions.lpsaActions);
180
181 if (hService)
182 CloseServiceHandle(hService);
183
184 if (hManager)
185 CloseServiceHandle(hManager);
186
187 return bResult;
188}
unsigned char BOOLEAN
BOOL ParseFailureArguments(IN LPCTSTR *ServiceArgs, IN INT ArgCount, OUT LPCTSTR *ppServiceName, OUT LPSERVICE_FAILURE_ACTIONS pFailureActions)
Definition: misc.c:259
#define SE_SHUTDOWN_PRIVILEGE
Definition: security.c:673
NTSYSAPI NTSTATUS NTAPI RtlAdjustPrivilege(_In_ ULONG Privilege, _In_ BOOLEAN NewValue, _In_ BOOLEAN ForThread, _Out_ PBOOLEAN OldValue)
VOID SetFailureUsage(VOID)
Definition: usage.c:249
#define SERVICE_START
Definition: winsvc.h:57

Referenced by ScControl().

◆ SetFailureUsage()

VOID SetFailureUsage ( VOID  )

Definition at line 249 of file usage.c.

250{
251 _tprintf(_T("DESCRIPTION:\n")
252 _T(" Changes the actions upon failure.\n")
253 _T("USAGE:\n")
254 _T(" sc <server> failure [service name] <option1> <option2>...\n")
255 _T("\n")
256 _T("OPTIONS:\n")
257 _T(" reset= <Length of period of no failures (in seconds)\n")
258 _T(" after which to reset the failure count to 0 (may be INFINITE)>\n")
259 _T(" (Must be used in conjunction with actions= )\n")
260 _T(" reboot= <Message broadcast before rebooting on failure>\n")
261 _T(" command= <Command line to be run on failure>\n")
262 _T(" actions= <Failure actions and their delay time (in milliseconds),\n")
263 _T(" separated by / (forward slash) -- e.g., run/5000/reboot/800\n")
264 _T(" Valid actions are <run|restart|reboot> >\n")
265 _T(" (Must be used in conjunction with the reset= option)\n"));
266}

Referenced by SetFailure().

◆ Start()

BOOL Start ( LPCTSTR  ServiceName,
LPCTSTR ServiceArgs,
INT  ArgCount 
)

Definition at line 12 of file start.c.

13{
14 SC_HANDLE hSCManager = NULL;
15 SC_HANDLE hSc = NULL;
16 LPSERVICE_STATUS_PROCESS pServiceInfo = NULL;
17 BOOL bResult = TRUE;
18
19#ifdef SCDBG
20 LPCTSTR *TmpArgs = ServiceArgs;
21 INT TmpCnt = ArgCount;
22 _tprintf(_T("service to control - %s\n"), ServiceName);
23 _tprintf(_T("Arguments:\n"));
24 while (TmpCnt)
25 {
26 _tprintf(_T(" %s\n"), *TmpArgs);
27 TmpArgs++;
28 TmpCnt--;
29 }
30 _tprintf(_T("\n"));
31#endif /* SCDBG */
32
34 NULL,
36 if (hSCManager == NULL)
37 {
38 _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
39 bResult = FALSE;
40 goto done;
41 }
42
46 if (hSc == NULL)
47 {
48 _tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError());
49 bResult = FALSE;
50 goto done;
51 }
52
53 if (!ArgCount)
54 {
55 ServiceArgs = NULL;
56 }
57
58 if (!StartService(hSc,
59 ArgCount,
60 ServiceArgs))
61 {
62 _tprintf(_T("[SC] StartService FAILED %lu:\n\n"), GetLastError());
63 bResult = FALSE;
64 goto done;
65 }
66
67 pServiceInfo = QueryService(ServiceName);
68 if (pServiceInfo != NULL)
69 {
71 NULL,
72 pServiceInfo,
73 TRUE);
74
75 HeapFree(GetProcessHeap(), 0, pServiceInfo);
76 }
77
78done:
79 if (bResult == FALSE)
81
82 if (hSc)
84
85 if (hSCManager)
87
88 return bResult;
89}
#define StartService
Definition: winsvc.h:585

◆ StartUsage()

VOID StartUsage ( VOID  )

Definition at line 93 of file usage.c.

94{
95 _tprintf(_T("DESCRIPTION:\n")
96 _T(" Starts a service running.\n")
97 _T("USAGE:\n")
98 _T(" sc <server> start [service name] <arg1> <arg2> ...\n"));
99}

Referenced by ScControl().

◆ StopUsage()

VOID StopUsage ( VOID  )

Definition at line 119 of file usage.c.

120{
121 _tprintf(_T("DESCRIPTION:\n")
122 _T(" Sends a STOP control request to a service.\n")
123 _T("USAGE:\n")
124 _T(" sc <server> stop [service name]\n"));
125}

Referenced by ScControl().