ReactOS 0.4.15-dev-5672-gf73ac17
CreateService.c File Reference
#include "precomp.h"
Include dependency graph for CreateService.c:

Go to the source code of this file.

Functions

static int MakeService (SC_HANDLE hScm, const wchar_t *serviceName, SC_HANDLE *hService, DWORD *tag)
 
static void DestroyService (SC_HANDLE hService)
 
static void Test_CreateService (void)
 
 START_TEST (CreateService)
 

Function Documentation

◆ DestroyService()

static void DestroyService ( SC_HANDLE  hService)
static

Definition at line 65 of file CreateService.c.

66{
67 LONG ret;
68
69 if (!hService)
70 return;
72 ret = DeleteService(hService);
73 ok(ret == TRUE, "DeleteService returned %ld, expected 1\n", ret);
75 || GetLastError() == ERROR_SUCCESS /* win2k3 */, "DeleteService GetLastError()=0x%08lx\n", GetLastError());
76
77 CloseServiceHandle(hService);
78}
#define ok(value,...)
Definition: atltest.h:57
#define ERROR_SUCCESS
Definition: deptool.c:10
#define TRUE
Definition: types.h:120
#define SetLastError(x)
Definition: compat.h:752
long LONG
Definition: pedump.c:60
BOOL WINAPI DeleteService(SC_HANDLE hService)
Definition: scm.c:921
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:580
int ret
DWORD WINAPI GetLastError(void)
Definition: except.c:1040
#define DNS_ERROR_RCODE_NXRRSET
Definition: winerror.h:1855

Referenced by Test_CreateService().

◆ MakeService()

static int MakeService ( SC_HANDLE  hScm,
const wchar_t serviceName,
SC_HANDLE *  hService,
DWORD tag 
)
static

Definition at line 10 of file CreateService.c.

11{
12 DWORD ret;
13 HKEY hKey = NULL;
14 DWORD type = 0, tagData = 0, tagSize;
15 wchar_t keyName[256];
16
18 *hService = CreateServiceW(
19 hScm,
21 NULL,
22 DELETE,
26 L"%systemroot%\\drivers\\win32k.sys",
27 L"advapi32_apitest_CreateService_Test_Group",
28 tag,
29 NULL,
30 NULL,
31 NULL);
32
33 ok(*hService != NULL, "Failed to create service, error=0x%08lx\n", GetLastError());
34 if (!*hService)
35 {
36 skip("No service; cannot proceed with CreateService test\n");
37 return 1;
38 }
39
41
42 ok(*tag != 0, "tag is zero, expected nonzero\n");
43
44 StringCbPrintfW(keyName, sizeof keyName, L"System\\CurrentControlSet\\Services\\%ls", serviceName);
46 ok(ret == ERROR_SUCCESS, "RegOpenKeyW failed with 0x%08lx\n", ret);
47 if (ret)
48 {
49 skip("No regkey; cannot proceed with CreateService test\n");
50 return 2;
51 }
52
53 tagSize = sizeof tagData;
54 ret = RegQueryValueExW(hKey, L"Tag", NULL, &type, (PBYTE)&tagData, &tagSize);
55 ok(ret == ERROR_SUCCESS, "RegQueryValueExW returned 0x%08lx\n", ret);
56 ok(type == REG_DWORD, "type=%lu, expected REG_DWORD\n", type);
57 ok(tagSize == sizeof tagData, "tagSize=%lu, expected 4\n", tagSize);
58 ok(tagData == *tag, "tag=%lu, but registry says %lu\n", *tag, tagData);
59
61
62 return 0;
63}
#define skip(...)
Definition: atltest.h:64
#define ok_err(error)
Definition: atltest.h:124
#define RegCloseKey(hKey)
Definition: registry.h:47
#define NULL
Definition: types.h:112
LONG WINAPI RegOpenKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:3291
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4121
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define DELETE
Definition: nt_native.h:57
#define L(x)
Definition: ntvdm.h:50
BYTE * PBYTE
Definition: pedump.c:66
SC_HANDLE WINAPI CreateServiceW(SC_HANDLE hSCManager, LPCWSTR lpServiceName, LPCWSTR lpDisplayName, DWORD dwDesiredAccess, DWORD dwServiceType, DWORD dwStartType, DWORD dwErrorControl, LPCWSTR lpBinaryPathName, LPCWSTR lpLoadOrderGroup, LPDWORD lpdwTagId, LPCWSTR lpDependencies, LPCWSTR lpServiceStartName, LPCWSTR lpPassword)
Definition: scm.c:812
#define REG_DWORD
Definition: sdbapi.c:596
STRSAFEAPI StringCbPrintfW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:557
Definition: ecma_167.h:138
char serviceName[]
Definition: tftpd.cpp:34
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define SERVICE_KERNEL_DRIVER
Definition: cmtypes.h:953
#define SERVICE_BOOT_START
Definition: cmtypes.h:975
#define SERVICE_ERROR_IGNORE
Definition: cmtypes.h:981

Referenced by Test_CreateService().

◆ START_TEST()

START_TEST ( CreateService  )

Definition at line 155 of file CreateService.c.

156{
158}
static void Test_CreateService(void)
Definition: CreateService.c:80

◆ Test_CreateService()

static void Test_CreateService ( void  )
static

Definition at line 80 of file CreateService.c.

81{
82 SC_HANDLE hScm = NULL;
83 SC_HANDLE hService1 = NULL, hService2 = NULL;
84 SC_HANDLE hService3 = NULL;
85 DWORD tag1 = 0, tag2 = 0;
86 DWORD tag3 = 785;
87
90 ok(hScm != NULL, "Failed to open service manager, error=0x%08lx\n", GetLastError());
91 if (!hScm)
92 {
93 skip("No service control manager; cannot proceed with CreateService test\n");
94 goto cleanup;
95 }
96
98
99 if (MakeService(hScm, L"advapi32_apitest_CreateService_Test_Service1", &hService1, &tag1))
100 goto cleanup;
101
102 if (MakeService(hScm, L"advapi32_apitest_CreateService_Test_Service2", &hService2, &tag2))
103 goto cleanup;
104
105 ok(tag1 != tag2, "tag1=%lu, tag2=%lu\n", tag1, tag2);
106
107 /* ask for a tag, but don't have a group */
108 hService3 = CreateServiceW(
109 hScm,
110 L"advapi32_apitest_CreateService_Test_Service2",
111 NULL,
112 DELETE,
116 L"%systemroot%\\drivers\\win32k.sys",
117 NULL,
118 &tag3,
119 NULL,
120 NULL,
121 NULL);
122 ok(hService3 == NULL, "hService3=%p\n", hService3);
123 ok(GetLastError() == ERROR_INVALID_PARAMETER, "error=%lu\n", GetLastError());
124 ok(tag3 == 785, "tag3=%lu\n", tag3);
125 DestroyService(hService3);
126
127 hService3 = CreateServiceW(
128 hScm,
129 L"advapi32_apitest_CreateService_Test_Service2",
130 NULL,
131 DELETE,
135 L"%systemroot%\\drivers\\win32k.sys",
136 L"",
137 &tag3,
138 NULL,
139 NULL,
140 NULL);
141 ok(hService3 == NULL, "hService3=%p\n", hService3);
142 ok(GetLastError() == ERROR_INVALID_PARAMETER, "error=%lu\n", GetLastError());
143 ok(tag3 == 785, "tag3=%lu\n", tag3);
144 DestroyService(hService3);
145
146cleanup:
147
148 DestroyService(hService2);
149 DestroyService(hService1);
150
151 if (hScm)
152 CloseServiceHandle(hScm);
153}
static void DestroyService(SC_HANDLE hService)
Definition: CreateService.c:65
static int MakeService(SC_HANDLE hScm, const wchar_t *serviceName, SC_HANDLE *hService, DWORD *tag)
Definition: CreateService.c:10
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
static void cleanup(void)
Definition: main.c:1335
SC_HANDLE WINAPI OpenSCManagerW(LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, DWORD dwDesiredAccess)
Definition: scm.c:2016
#define SC_MANAGER_CREATE_SERVICE
Definition: winsvc.h:15

Referenced by START_TEST().