Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Win32 advapi functions |
| 3 | * |
| 4 | * Copyright 1995 Sven Verdoolaege |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2.1 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 21 | #include <stdarg.h> |
James Juran | f4d5fef | 2001-01-26 20:43:40 +0000 | [diff] [blame] | 22 | #include <string.h> |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 23 | #include <time.h> |
Patrik Stridvall | 4a73973 | 1999-07-04 11:01:21 +0000 | [diff] [blame] | 24 | |
Jim Aston | 2e1cafa | 1999-03-14 16:35:05 +0000 | [diff] [blame] | 25 | #include "windef.h" |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 26 | #include "winbase.h" |
Patrik Stridvall | 4a73973 | 1999-07-04 11:01:21 +0000 | [diff] [blame] | 27 | #include "winsvc.h" |
Marcus Meissner | 317af32 | 1999-02-17 13:51:06 +0000 | [diff] [blame] | 28 | #include "winerror.h" |
Michael McCormack | 75a8413 | 1999-11-21 00:58:14 +0000 | [diff] [blame] | 29 | #include "winreg.h" |
Alexandre Julliard | c7e7df8 | 2000-08-14 14:41:19 +0000 | [diff] [blame] | 30 | #include "wine/unicode.h" |
Marcus Meissner | 317af32 | 1999-02-17 13:51:06 +0000 | [diff] [blame] | 31 | #include "heap.h" |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 32 | #include "wine/debug.h" |
Matthew Davison | 6f2a071 | 2003-01-20 23:23:12 +0000 | [diff] [blame] | 33 | #include "winternl.h" |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 34 | |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 35 | WINE_DEFAULT_DEBUG_CHANNEL(advapi); |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 36 | |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 37 | static DWORD start_dwNumServiceArgs; |
| 38 | static LPWSTR *start_lpServiceArgVectors; |
| 39 | |
Alexandre Julliard | b10dcfe | 2003-10-10 00:05:49 +0000 | [diff] [blame] | 40 | static const WCHAR _ServiceStartDataW[] = {'A','D','V','A','P','I','_','S', |
| 41 | 'e','r','v','i','c','e','S','t', |
| 42 | 'a','r','t','D','a','t','a',0}; |
| 43 | |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 44 | /****************************************************************************** |
Patrik Stridvall | 54fe838 | 2000-04-06 20:21:16 +0000 | [diff] [blame] | 45 | * EnumServicesStatusA [ADVAPI32.@] |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 46 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 47 | BOOL WINAPI |
Patrik Stridvall | 4a73973 | 1999-07-04 11:01:21 +0000 | [diff] [blame] | 48 | EnumServicesStatusA( SC_HANDLE hSCManager, DWORD dwServiceType, |
Patrik Stridvall | 54fe838 | 2000-04-06 20:21:16 +0000 | [diff] [blame] | 49 | DWORD dwServiceState, LPENUM_SERVICE_STATUSA lpServices, |
| 50 | DWORD cbBufSize, LPDWORD pcbBytesNeeded, |
| 51 | LPDWORD lpServicesReturned, LPDWORD lpResumeHandle ) |
Michael Stefaniuc | cbacde5 | 2002-10-25 19:17:33 +0000 | [diff] [blame] | 52 | { FIXME("%p type=%lx state=%lx %p %lx %p %p %p\n", hSCManager, |
Patrik Stridvall | 54fe838 | 2000-04-06 20:21:16 +0000 | [diff] [blame] | 53 | dwServiceType, dwServiceState, lpServices, cbBufSize, |
| 54 | pcbBytesNeeded, lpServicesReturned, lpResumeHandle); |
| 55 | SetLastError (ERROR_ACCESS_DENIED); |
François Gouget | 97ad5a7 | 2001-01-02 20:20:34 +0000 | [diff] [blame] | 56 | return FALSE; |
Patrik Stridvall | 54fe838 | 2000-04-06 20:21:16 +0000 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | /****************************************************************************** |
| 60 | * EnumServicesStatusW [ADVAPI32.@] |
| 61 | */ |
| 62 | BOOL WINAPI |
| 63 | EnumServicesStatusW( SC_HANDLE hSCManager, DWORD dwServiceType, |
| 64 | DWORD dwServiceState, LPENUM_SERVICE_STATUSW lpServices, |
| 65 | DWORD cbBufSize, LPDWORD pcbBytesNeeded, |
| 66 | LPDWORD lpServicesReturned, LPDWORD lpResumeHandle ) |
Michael Stefaniuc | cbacde5 | 2002-10-25 19:17:33 +0000 | [diff] [blame] | 67 | { FIXME("%p type=%lx state=%lx %p %lx %p %p %p\n", hSCManager, |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 68 | dwServiceType, dwServiceState, lpServices, cbBufSize, |
| 69 | pcbBytesNeeded, lpServicesReturned, lpResumeHandle); |
| 70 | SetLastError (ERROR_ACCESS_DENIED); |
François Gouget | 97ad5a7 | 2001-01-02 20:20:34 +0000 | [diff] [blame] | 71 | return FALSE; |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 72 | } |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 73 | |
| 74 | /****************************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 75 | * StartServiceCtrlDispatcherA [ADVAPI32.@] |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 76 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 77 | BOOL WINAPI |
| 78 | StartServiceCtrlDispatcherA( LPSERVICE_TABLE_ENTRYA servent ) |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 79 | { |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 80 | LPSERVICE_MAIN_FUNCTIONA fpMain; |
| 81 | HANDLE wait; |
| 82 | DWORD dwNumServiceArgs ; |
| 83 | LPWSTR *lpArgVecW; |
| 84 | LPSTR *lpArgVecA; |
| 85 | int i; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 86 | |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 87 | TRACE("(%p)\n", servent); |
Alexandre Julliard | b10dcfe | 2003-10-10 00:05:49 +0000 | [diff] [blame] | 88 | wait = OpenSemaphoreW(SEMAPHORE_ALL_ACCESS, FALSE, _ServiceStartDataW); |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 89 | if(wait == 0) |
| 90 | { |
| 91 | ERR("Couldn't find wait semaphore\n"); |
| 92 | ERR("perhaps you need to start services using StartService\n"); |
| 93 | return FALSE; |
| 94 | } |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 95 | |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 96 | dwNumServiceArgs = start_dwNumServiceArgs; |
| 97 | lpArgVecW = start_lpServiceArgVectors; |
| 98 | |
| 99 | ReleaseSemaphore(wait, 1, NULL); |
| 100 | |
| 101 | /* Convert the Unicode arg vectors back to ASCII */ |
| 102 | if(dwNumServiceArgs) |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 103 | lpArgVecA = (LPSTR*) HeapAlloc( GetProcessHeap(), 0, |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 104 | dwNumServiceArgs*sizeof(LPSTR) ); |
| 105 | else |
| 106 | lpArgVecA = NULL; |
| 107 | |
| 108 | for(i=0; i<dwNumServiceArgs; i++) |
| 109 | lpArgVecA[i]=HEAP_strdupWtoA(GetProcessHeap(), 0, lpArgVecW[i]); |
| 110 | |
| 111 | /* FIXME: should we blindly start all services? */ |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 112 | while (servent->lpServiceName) { |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 113 | TRACE("%s at %p)\n", debugstr_a(servent->lpServiceName),servent); |
| 114 | fpMain = servent->lpServiceProc; |
| 115 | |
| 116 | /* try to start the service */ |
| 117 | fpMain( dwNumServiceArgs, lpArgVecA); |
| 118 | |
| 119 | servent++; |
| 120 | } |
| 121 | |
| 122 | if(dwNumServiceArgs) |
| 123 | { |
| 124 | /* free arg strings */ |
| 125 | for(i=0; i<dwNumServiceArgs; i++) |
| 126 | HeapFree(GetProcessHeap(), 0, lpArgVecA[i]); |
| 127 | HeapFree(GetProcessHeap(), 0, lpArgVecA); |
| 128 | } |
| 129 | |
| 130 | return TRUE; |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 131 | } |
| 132 | |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 133 | /****************************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 134 | * StartServiceCtrlDispatcherW [ADVAPI32.@] |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 135 | * |
| 136 | * PARAMS |
| 137 | * servent [] |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 138 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 139 | BOOL WINAPI |
| 140 | StartServiceCtrlDispatcherW( LPSERVICE_TABLE_ENTRYW servent ) |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 141 | { |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 142 | LPSERVICE_MAIN_FUNCTIONW fpMain; |
| 143 | HANDLE wait; |
| 144 | DWORD dwNumServiceArgs ; |
| 145 | LPWSTR *lpServiceArgVectors ; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 146 | |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 147 | TRACE("(%p)\n", servent); |
Matthew Davison | 620323e | 2003-01-24 00:45:51 +0000 | [diff] [blame] | 148 | wait = OpenSemaphoreW(SEMAPHORE_ALL_ACCESS, FALSE, _ServiceStartDataW); |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 149 | if(wait == 0) |
| 150 | { |
| 151 | ERR("Couldn't find wait semaphore\n"); |
| 152 | ERR("perhaps you need to start services using StartService\n"); |
| 153 | return FALSE; |
| 154 | } |
| 155 | |
| 156 | dwNumServiceArgs = start_dwNumServiceArgs; |
| 157 | lpServiceArgVectors = start_lpServiceArgVectors; |
| 158 | |
| 159 | ReleaseSemaphore(wait, 1, NULL); |
| 160 | |
| 161 | /* FIXME: should we blindly start all services? */ |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 162 | while (servent->lpServiceName) { |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 163 | TRACE("%s at %p)\n", debugstr_w(servent->lpServiceName),servent); |
| 164 | fpMain = servent->lpServiceProc; |
| 165 | |
| 166 | /* try to start the service */ |
| 167 | fpMain( dwNumServiceArgs, lpServiceArgVectors); |
| 168 | |
| 169 | servent++; |
| 170 | } |
| 171 | |
| 172 | return TRUE; |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 173 | } |
| 174 | |
Matthew Becker | 6d59445 | 1999-01-30 12:54:32 +0000 | [diff] [blame] | 175 | /****************************************************************************** |
Uwe Bonnes | 574d4a9 | 2003-01-14 19:31:44 +0000 | [diff] [blame] | 176 | * LockServiceDatabase [ADVAPI32.@] |
| 177 | */ |
| 178 | LPVOID WINAPI LockServiceDatabase (SC_HANDLE hSCManager) |
| 179 | { |
| 180 | FIXME("%p\n",hSCManager); |
| 181 | return (SC_HANDLE)0xcacacafe; |
| 182 | } |
| 183 | |
| 184 | /****************************************************************************** |
| 185 | * UnlockServiceDatabase [ADVAPI32.@] |
| 186 | */ |
| 187 | BOOL WINAPI UnlockServiceDatabase (LPVOID ScLock) |
| 188 | { |
| 189 | FIXME(": %p\n",ScLock); |
| 190 | return TRUE; |
| 191 | } |
| 192 | |
| 193 | /****************************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 194 | * RegisterServiceCtrlHandlerA [ADVAPI32.@] |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 195 | */ |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 196 | SERVICE_STATUS_HANDLE WINAPI |
Patrik Stridvall | 4a73973 | 1999-07-04 11:01:21 +0000 | [diff] [blame] | 197 | RegisterServiceCtrlHandlerA( LPCSTR lpServiceName, |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 198 | LPHANDLER_FUNCTION lpfHandler ) |
Alexandre Julliard | 9fe7a25 | 1999-05-14 08:17:14 +0000 | [diff] [blame] | 199 | { FIXME("%s %p\n", lpServiceName, lpfHandler); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 200 | return 0xcacacafe; |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 201 | } |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 202 | |
| 203 | /****************************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 204 | * RegisterServiceCtrlHandlerW [ADVAPI32.@] |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 205 | * |
| 206 | * PARAMS |
| 207 | * lpServiceName [] |
| 208 | * lpfHandler [] |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 209 | */ |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 210 | SERVICE_STATUS_HANDLE WINAPI |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 211 | RegisterServiceCtrlHandlerW( LPCWSTR lpServiceName, |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 212 | LPHANDLER_FUNCTION lpfHandler ) |
Alexandre Julliard | 9fe7a25 | 1999-05-14 08:17:14 +0000 | [diff] [blame] | 213 | { FIXME("%s %p\n", debugstr_w(lpServiceName), lpfHandler); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 214 | return 0xcacacafe; |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 215 | } |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 216 | |
| 217 | /****************************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 218 | * SetServiceStatus [ADVAPI32.@] |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 219 | * |
| 220 | * PARAMS |
| 221 | * hService [] |
| 222 | * lpStatus [] |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 223 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 224 | BOOL WINAPI |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 225 | SetServiceStatus( SERVICE_STATUS_HANDLE hService, LPSERVICE_STATUS lpStatus ) |
François Gouget | 97ad5a7 | 2001-01-02 20:20:34 +0000 | [diff] [blame] | 226 | { FIXME("0x%lx %p\n",hService, lpStatus); |
Alexandre Julliard | 9fe7a25 | 1999-05-14 08:17:14 +0000 | [diff] [blame] | 227 | TRACE("\tType:%lx\n",lpStatus->dwServiceType); |
| 228 | TRACE("\tState:%lx\n",lpStatus->dwCurrentState); |
| 229 | TRACE("\tControlAccepted:%lx\n",lpStatus->dwControlsAccepted); |
| 230 | TRACE("\tExitCode:%lx\n",lpStatus->dwWin32ExitCode); |
| 231 | TRACE("\tServiceExitCode:%lx\n",lpStatus->dwServiceSpecificExitCode); |
| 232 | TRACE("\tCheckPoint:%lx\n",lpStatus->dwCheckPoint); |
| 233 | TRACE("\tWaitHint:%lx\n",lpStatus->dwWaitHint); |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 234 | return TRUE; |
| 235 | } |
| 236 | |
| 237 | /****************************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 238 | * OpenSCManagerA [ADVAPI32.@] |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 239 | */ |
Patrik Stridvall | 4a73973 | 1999-07-04 11:01:21 +0000 | [diff] [blame] | 240 | SC_HANDLE WINAPI |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 241 | OpenSCManagerA( LPCSTR lpMachineName, LPCSTR lpDatabaseName, |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 242 | DWORD dwDesiredAccess ) |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 243 | { |
Matthew Davison | 6f2a071 | 2003-01-20 23:23:12 +0000 | [diff] [blame] | 244 | UNICODE_STRING lpMachineNameW; |
| 245 | UNICODE_STRING lpDatabaseNameW; |
| 246 | SC_HANDLE ret; |
| 247 | |
| 248 | RtlCreateUnicodeStringFromAsciiz (&lpMachineNameW,lpMachineName); |
| 249 | RtlCreateUnicodeStringFromAsciiz (&lpDatabaseNameW,lpDatabaseName); |
| 250 | ret = OpenSCManagerW(lpMachineNameW.Buffer,lpDatabaseNameW.Buffer, dwDesiredAccess); |
| 251 | RtlFreeUnicodeString(&lpDatabaseNameW); |
| 252 | RtlFreeUnicodeString(&lpMachineNameW); |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 253 | return ret; |
| 254 | } |
| 255 | |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 256 | /****************************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 257 | * OpenSCManagerW [ADVAPI32.@] |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 258 | * Establishes a connection to the service control manager and opens database |
| 259 | * |
| 260 | * NOTES |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 261 | * This should return a SC_HANDLE |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 262 | * |
| 263 | * PARAMS |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 264 | * lpMachineName [I] Pointer to machine name string |
| 265 | * lpDatabaseName [I] Pointer to database name string |
| 266 | * dwDesiredAccess [I] Type of access |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 267 | * |
| 268 | * RETURNS |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 269 | * Success: Handle to service control manager database |
| 270 | * Failure: NULL |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 271 | */ |
Patrik Stridvall | 4a73973 | 1999-07-04 11:01:21 +0000 | [diff] [blame] | 272 | SC_HANDLE WINAPI |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 273 | OpenSCManagerW( LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 274 | DWORD dwDesiredAccess ) |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 275 | { |
Mike McCormack | 9b513ad | 2003-12-02 03:48:53 +0000 | [diff] [blame^] | 276 | const WCHAR szKey[] = { 'S','y','s','t','e','m','\\', |
| 277 | 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\', |
| 278 | 'S','e','r','v','i','c','e','s','\\',0 }; |
| 279 | HKEY hReg, hKey = NULL; |
Michael McCormack | 75a8413 | 1999-11-21 00:58:14 +0000 | [diff] [blame] | 280 | LONG r; |
| 281 | |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 282 | TRACE("(%s,%s,0x%08lx)\n", debugstr_w(lpMachineName), |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 283 | debugstr_w(lpDatabaseName), dwDesiredAccess); |
Michael McCormack | 75a8413 | 1999-11-21 00:58:14 +0000 | [diff] [blame] | 284 | |
| 285 | /* |
| 286 | * FIXME: what is lpDatabaseName? |
| 287 | * It should be set to "SERVICES_ACTIVE_DATABASE" according to |
| 288 | * docs, but what if it isn't? |
| 289 | */ |
| 290 | |
Mike McCormack | 9b513ad | 2003-12-02 03:48:53 +0000 | [diff] [blame^] | 291 | r = RegConnectRegistryW(lpMachineName,HKEY_LOCAL_MACHINE,&hReg); |
| 292 | if (r==ERROR_SUCCESS) |
| 293 | { |
| 294 | r = RegOpenKeyExW(hReg, szKey, 0, dwDesiredAccess, &hKey ); |
| 295 | RegCloseKey( hReg ); |
| 296 | } |
Michael McCormack | 75a8413 | 1999-11-21 00:58:14 +0000 | [diff] [blame] | 297 | |
Mike McCormack | 9b513ad | 2003-12-02 03:48:53 +0000 | [diff] [blame^] | 298 | TRACE("returning %p\n", hKey); |
Michael McCormack | 75a8413 | 1999-11-21 00:58:14 +0000 | [diff] [blame] | 299 | |
| 300 | return hKey; |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 304 | /****************************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 305 | * AllocateLocallyUniqueId [ADVAPI32.@] |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 306 | * |
| 307 | * PARAMS |
| 308 | * lpluid [] |
| 309 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 310 | BOOL WINAPI |
Juergen Schmied | 1ed51af | 1999-02-12 17:47:07 +0000 | [diff] [blame] | 311 | AllocateLocallyUniqueId( PLUID lpluid ) |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 312 | { |
Francois Gouget | ea31cf0 | 2001-11-20 18:52:20 +0000 | [diff] [blame] | 313 | lpluid->LowPart = time(NULL); |
| 314 | lpluid->HighPart = 0; |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 315 | return TRUE; |
| 316 | } |
| 317 | |
| 318 | |
| 319 | /****************************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 320 | * ControlService [ADVAPI32.@] |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 321 | * Sends a control code to a Win32-based service. |
| 322 | * |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 323 | * PARAMS |
| 324 | * hService [] |
| 325 | * dwControl [] |
| 326 | * lpServiceStatus [] |
| 327 | * |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 328 | * RETURNS STD |
| 329 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 330 | BOOL WINAPI |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 331 | ControlService( SC_HANDLE hService, DWORD dwControl, |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 332 | LPSERVICE_STATUS lpServiceStatus ) |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 333 | { |
Michael Stefaniuc | cbacde5 | 2002-10-25 19:17:33 +0000 | [diff] [blame] | 334 | FIXME("(%p,%ld,%p): stub\n",hService,dwControl,lpServiceStatus); |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 335 | return TRUE; |
| 336 | } |
| 337 | |
| 338 | |
| 339 | /****************************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 340 | * CloseServiceHandle [ADVAPI32.@] |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 341 | * Close handle to service or service control manager |
| 342 | * |
| 343 | * PARAMS |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 344 | * hSCObject [I] Handle to service or service control manager database |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 345 | * |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 346 | * RETURNS STD |
| 347 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 348 | BOOL WINAPI |
Patrik Stridvall | 4a73973 | 1999-07-04 11:01:21 +0000 | [diff] [blame] | 349 | CloseServiceHandle( SC_HANDLE hSCObject ) |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 350 | { |
Michael Stefaniuc | cbacde5 | 2002-10-25 19:17:33 +0000 | [diff] [blame] | 351 | TRACE("(%p)\n", hSCObject); |
Michael McCormack | 75a8413 | 1999-11-21 00:58:14 +0000 | [diff] [blame] | 352 | |
| 353 | RegCloseKey(hSCObject); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 354 | |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 355 | return TRUE; |
| 356 | } |
| 357 | |
| 358 | |
| 359 | /****************************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 360 | * OpenServiceA [ADVAPI32.@] |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 361 | */ |
Patrik Stridvall | 4a73973 | 1999-07-04 11:01:21 +0000 | [diff] [blame] | 362 | SC_HANDLE WINAPI |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 363 | OpenServiceA( SC_HANDLE hSCManager, LPCSTR lpServiceName, |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 364 | DWORD dwDesiredAccess ) |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 365 | { |
Matthew Davison | 6f2a071 | 2003-01-20 23:23:12 +0000 | [diff] [blame] | 366 | UNICODE_STRING lpServiceNameW; |
François Gouget | 97ad5a7 | 2001-01-02 20:20:34 +0000 | [diff] [blame] | 367 | SC_HANDLE ret; |
Matthew Davison | 6f2a071 | 2003-01-20 23:23:12 +0000 | [diff] [blame] | 368 | RtlCreateUnicodeStringFromAsciiz (&lpServiceNameW,lpServiceName); |
Michael McCormack | 75a8413 | 1999-11-21 00:58:14 +0000 | [diff] [blame] | 369 | if(lpServiceName) |
| 370 | TRACE("Request for service %s\n",lpServiceName); |
| 371 | else |
| 372 | return FALSE; |
Matthew Davison | 6f2a071 | 2003-01-20 23:23:12 +0000 | [diff] [blame] | 373 | ret = OpenServiceW( hSCManager, lpServiceNameW.Buffer, dwDesiredAccess); |
| 374 | RtlFreeUnicodeString(&lpServiceNameW); |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 375 | return ret; |
| 376 | } |
| 377 | |
| 378 | |
| 379 | /****************************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 380 | * OpenServiceW [ADVAPI32.@] |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 381 | * Opens a handle to an existing service |
| 382 | * |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 383 | * PARAMS |
| 384 | * hSCManager [] |
| 385 | * lpServiceName [] |
| 386 | * dwDesiredAccess [] |
| 387 | * |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 388 | * RETURNS |
| 389 | * Success: Handle to the service |
| 390 | * Failure: NULL |
| 391 | */ |
Patrik Stridvall | 4a73973 | 1999-07-04 11:01:21 +0000 | [diff] [blame] | 392 | SC_HANDLE WINAPI |
| 393 | OpenServiceW(SC_HANDLE hSCManager, LPCWSTR lpServiceName, |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 394 | DWORD dwDesiredAccess) |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 395 | { |
Michael McCormack | 75a8413 | 1999-11-21 00:58:14 +0000 | [diff] [blame] | 396 | HKEY hKey; |
| 397 | long r; |
| 398 | |
Michael Stefaniuc | cbacde5 | 2002-10-25 19:17:33 +0000 | [diff] [blame] | 399 | TRACE("(%p,%p,%ld)\n",hSCManager, lpServiceName, |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 400 | dwDesiredAccess); |
Michael McCormack | 75a8413 | 1999-11-21 00:58:14 +0000 | [diff] [blame] | 401 | |
Michael McCormack | 75a8413 | 1999-11-21 00:58:14 +0000 | [diff] [blame] | 402 | /* FIXME: dwDesiredAccess may need some processing */ |
Mike McCormack | 9b513ad | 2003-12-02 03:48:53 +0000 | [diff] [blame^] | 403 | r = RegOpenKeyExW(hSCManager, lpServiceName, 0, dwDesiredAccess, &hKey ); |
Michael McCormack | 75a8413 | 1999-11-21 00:58:14 +0000 | [diff] [blame] | 404 | if (r!=ERROR_SUCCESS) |
| 405 | return 0; |
| 406 | |
Michael Stefaniuc | cbacde5 | 2002-10-25 19:17:33 +0000 | [diff] [blame] | 407 | TRACE("returning %p\n",hKey); |
Michael McCormack | 75a8413 | 1999-11-21 00:58:14 +0000 | [diff] [blame] | 408 | |
| 409 | return hKey; |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 410 | } |
| 411 | |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 412 | /****************************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 413 | * CreateServiceW [ADVAPI32.@] |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 414 | */ |
| 415 | SC_HANDLE WINAPI |
Peter Hunnisett | 565b008 | 2000-09-19 02:43:00 +0000 | [diff] [blame] | 416 | CreateServiceW( SC_HANDLE hSCManager, LPCWSTR lpServiceName, |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 417 | LPCWSTR lpDisplayName, DWORD dwDesiredAccess, |
| 418 | DWORD dwServiceType, DWORD dwStartType, |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 419 | DWORD dwErrorControl, LPCWSTR lpBinaryPathName, |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 420 | LPCWSTR lpLoadOrderGroup, LPDWORD lpdwTagId, |
| 421 | LPCWSTR lpDependencies, LPCWSTR lpServiceStartName, |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 422 | LPCWSTR lpPassword ) |
| 423 | { |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 424 | HKEY hKey; |
| 425 | LONG r; |
| 426 | DWORD dp; |
Mike McCormack | 9b513ad | 2003-12-02 03:48:53 +0000 | [diff] [blame^] | 427 | const WCHAR szDisplayName[] = { 'D','i','s','p','l','a','y','N','a','m','e', 0 }; |
| 428 | const WCHAR szType[] = {'T','y','p','e',0}; |
| 429 | const WCHAR szStart[] = {'S','t','a','r','t',0}; |
| 430 | const WCHAR szError[] = {'E','r','r','o','r','C','o','n','t','r','o','l', 0}; |
| 431 | const WCHAR szImagePath[] = {'I','m','a','g','e','P','a','t','h',0}; |
| 432 | const WCHAR szGroup[] = {'G','r','o','u','p',0}; |
| 433 | const WCHAR szDependencies[] = { 'D','e','p','e','n','d','e','n','c','i','e','s',0}; |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 434 | |
Mike McCormack | 9b513ad | 2003-12-02 03:48:53 +0000 | [diff] [blame^] | 435 | FIXME("%p %s %s\n", hSCManager, |
| 436 | debugstr_w(lpServiceName), debugstr_w(lpDisplayName)); |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 437 | |
Mike McCormack | 9b513ad | 2003-12-02 03:48:53 +0000 | [diff] [blame^] | 438 | r = RegCreateKeyExW(hSCManager, lpServiceName, 0, NULL, |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 439 | REG_OPTION_NON_VOLATILE, dwDesiredAccess, NULL, &hKey, &dp); |
| 440 | if (r!=ERROR_SUCCESS) |
| 441 | return 0; |
| 442 | if (dp != REG_CREATED_NEW_KEY) |
| 443 | return 0; |
| 444 | |
| 445 | if(lpDisplayName) |
| 446 | { |
Mike McCormack | 9b513ad | 2003-12-02 03:48:53 +0000 | [diff] [blame^] | 447 | r = RegSetValueExW(hKey, szDisplayName, 0, REG_SZ, (LPBYTE)lpDisplayName, |
| 448 | (strlenW(lpDisplayName)+1)*sizeof(WCHAR) ); |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 449 | if (r!=ERROR_SUCCESS) |
| 450 | return 0; |
| 451 | } |
| 452 | |
Mike McCormack | 9b513ad | 2003-12-02 03:48:53 +0000 | [diff] [blame^] | 453 | r = RegSetValueExW(hKey, szType, 0, REG_DWORD, (LPVOID)&dwServiceType, sizeof (DWORD) ); |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 454 | if (r!=ERROR_SUCCESS) |
| 455 | return 0; |
| 456 | |
Mike McCormack | 9b513ad | 2003-12-02 03:48:53 +0000 | [diff] [blame^] | 457 | r = RegSetValueExW(hKey, szStart, 0, REG_DWORD, (LPVOID)&dwStartType, sizeof (DWORD) ); |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 458 | if (r!=ERROR_SUCCESS) |
| 459 | return 0; |
| 460 | |
Mike McCormack | 9b513ad | 2003-12-02 03:48:53 +0000 | [diff] [blame^] | 461 | r = RegSetValueExW(hKey, szError, 0, REG_DWORD, |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 462 | (LPVOID)&dwErrorControl, sizeof (DWORD) ); |
| 463 | if (r!=ERROR_SUCCESS) |
| 464 | return 0; |
| 465 | |
| 466 | if(lpBinaryPathName) |
| 467 | { |
Mike McCormack | 9b513ad | 2003-12-02 03:48:53 +0000 | [diff] [blame^] | 468 | r = RegSetValueExW(hKey, szImagePath, 0, REG_SZ, (LPBYTE)lpBinaryPathName, |
| 469 | (strlenW(lpBinaryPathName)+1)*sizeof(WCHAR) ); |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 470 | if (r!=ERROR_SUCCESS) |
| 471 | return 0; |
| 472 | } |
| 473 | |
| 474 | if(lpLoadOrderGroup) |
| 475 | { |
Mike McCormack | 9b513ad | 2003-12-02 03:48:53 +0000 | [diff] [blame^] | 476 | r = RegSetValueExW(hKey, szGroup, 0, REG_SZ, (LPBYTE)lpLoadOrderGroup, |
| 477 | (strlenW(lpLoadOrderGroup)+1)*sizeof(WCHAR) ); |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 478 | if (r!=ERROR_SUCCESS) |
| 479 | return 0; |
| 480 | } |
| 481 | |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 482 | if(lpDependencies) |
| 483 | { |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 484 | DWORD len = 0; |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 485 | |
| 486 | /* determine the length of a double null terminated multi string */ |
| 487 | do { |
Mike McCormack | 9b513ad | 2003-12-02 03:48:53 +0000 | [diff] [blame^] | 488 | len += (strlenW(&lpDependencies[len])+1); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 489 | } while (lpDependencies[len++]); |
| 490 | |
Mike McCormack | 9b513ad | 2003-12-02 03:48:53 +0000 | [diff] [blame^] | 491 | r = RegSetValueExW(hKey, szDependencies, 0, REG_MULTI_SZ, |
| 492 | (LPBYTE)lpDependencies, len ); |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 493 | if (r!=ERROR_SUCCESS) |
| 494 | return 0; |
| 495 | } |
| 496 | |
| 497 | if(lpPassword) |
| 498 | { |
| 499 | FIXME("Don't know how to add a Password for a service.\n"); |
| 500 | } |
| 501 | |
| 502 | if(lpServiceStartName) |
| 503 | { |
| 504 | FIXME("Don't know how to add a ServiceStartName for a service.\n"); |
| 505 | } |
| 506 | |
| 507 | return hKey; |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | |
Mike McCormack | 9b513ad | 2003-12-02 03:48:53 +0000 | [diff] [blame^] | 511 | static inline LPWSTR SERV_dup( LPCSTR str ) |
| 512 | { |
| 513 | UINT len; |
| 514 | LPWSTR wstr; |
| 515 | |
| 516 | if( !str ) |
| 517 | return NULL; |
| 518 | len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 ); |
| 519 | wstr = HeapAlloc( GetProcessHeap(), 0, len*sizeof (WCHAR) ); |
| 520 | MultiByteToWideChar( CP_ACP, 0, str, -1, wstr, len ); |
| 521 | return wstr; |
| 522 | } |
| 523 | |
| 524 | static inline LPWSTR SERV_dupmulti( LPCSTR str ) |
| 525 | { |
| 526 | UINT len = 0, n = 0; |
| 527 | LPWSTR wstr; |
| 528 | |
| 529 | do { |
| 530 | len += MultiByteToWideChar( CP_ACP, 0, &str[n], -1, NULL, 0 ); |
| 531 | n += (strlen( &str[n] ) + 1); |
| 532 | } while (str[n]); |
| 533 | len++; |
| 534 | n++; |
| 535 | |
| 536 | wstr = HeapAlloc( GetProcessHeap(), 0, len*sizeof (WCHAR) ); |
| 537 | MultiByteToWideChar( CP_ACP, 0, str, n, wstr, len ); |
| 538 | return wstr; |
| 539 | } |
| 540 | |
| 541 | static inline VOID SERV_free( LPWSTR wstr ) |
| 542 | { |
| 543 | HeapFree( GetProcessHeap(), 0, wstr ); |
| 544 | } |
| 545 | |
| 546 | /****************************************************************************** |
| 547 | * CreateServiceA [ADVAPI32.@] |
| 548 | */ |
| 549 | SC_HANDLE WINAPI |
| 550 | CreateServiceA( SC_HANDLE hSCManager, LPCSTR lpServiceName, |
| 551 | LPCSTR lpDisplayName, DWORD dwDesiredAccess, |
| 552 | DWORD dwServiceType, DWORD dwStartType, |
| 553 | DWORD dwErrorControl, LPCSTR lpBinaryPathName, |
| 554 | LPCSTR lpLoadOrderGroup, LPDWORD lpdwTagId, |
| 555 | LPCSTR lpDependencies, LPCSTR lpServiceStartName, |
| 556 | LPCSTR lpPassword ) |
| 557 | { |
| 558 | LPWSTR lpServiceNameW, lpDisplayNameW, lpBinaryPathNameW, |
| 559 | lpLoadOrderGroupW, lpDependenciesW, lpServiceStartNameW, lpPasswordW; |
| 560 | SC_HANDLE r; |
| 561 | |
| 562 | TRACE("%p %s %s\n", hSCManager, |
| 563 | debugstr_a(lpServiceName), debugstr_a(lpDisplayName)); |
| 564 | |
| 565 | lpServiceNameW = SERV_dup( lpServiceName ); |
| 566 | lpDisplayNameW = SERV_dup( lpDisplayName ); |
| 567 | lpBinaryPathNameW = SERV_dup( lpBinaryPathName ); |
| 568 | lpLoadOrderGroupW = SERV_dup( lpLoadOrderGroup ); |
| 569 | lpDependenciesW = SERV_dupmulti( lpDependencies ); |
| 570 | lpServiceStartNameW = SERV_dup( lpServiceStartName ); |
| 571 | lpPasswordW = SERV_dup( lpPassword ); |
| 572 | |
| 573 | r = CreateServiceW( hSCManager, lpServiceNameW, lpDisplayNameW, |
| 574 | dwDesiredAccess, dwServiceType, dwStartType, dwErrorControl, |
| 575 | lpBinaryPathNameW, lpLoadOrderGroupW, lpdwTagId, |
| 576 | lpDependenciesW, lpServiceStartNameW, lpPasswordW ); |
| 577 | |
| 578 | SERV_free( lpServiceNameW ); |
| 579 | SERV_free( lpDisplayNameW ); |
| 580 | SERV_free( lpBinaryPathNameW ); |
| 581 | SERV_free( lpLoadOrderGroupW ); |
| 582 | SERV_free( lpDependenciesW ); |
| 583 | SERV_free( lpServiceStartNameW ); |
| 584 | SERV_free( lpPasswordW ); |
| 585 | |
| 586 | return r; |
| 587 | } |
| 588 | |
| 589 | |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 590 | /****************************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 591 | * DeleteService [ADVAPI32.@] |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 592 | * |
| 593 | * PARAMS |
| 594 | * hService [I] Handle to service |
| 595 | * |
| 596 | * RETURNS STD |
| 597 | * |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 598 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 599 | BOOL WINAPI |
Patrik Stridvall | 4a73973 | 1999-07-04 11:01:21 +0000 | [diff] [blame] | 600 | DeleteService( SC_HANDLE hService ) |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 601 | { |
Michael Stefaniuc | cbacde5 | 2002-10-25 19:17:33 +0000 | [diff] [blame] | 602 | FIXME("(%p): stub\n",hService); |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 603 | return TRUE; |
| 604 | } |
| 605 | |
| 606 | |
| 607 | /****************************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 608 | * StartServiceA [ADVAPI32.@] |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 609 | * |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 610 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 611 | BOOL WINAPI |
Patrik Stridvall | 4a73973 | 1999-07-04 11:01:21 +0000 | [diff] [blame] | 612 | StartServiceA( SC_HANDLE hService, DWORD dwNumServiceArgs, |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 613 | LPCSTR *lpServiceArgVectors ) |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 614 | { |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 615 | LPWSTR *lpwstr=NULL; |
Matthew Davison | 60009b9 | 2003-01-23 23:07:38 +0000 | [diff] [blame] | 616 | UNICODE_STRING usBuffer; |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 617 | int i; |
| 618 | |
Michael Stefaniuc | cbacde5 | 2002-10-25 19:17:33 +0000 | [diff] [blame] | 619 | TRACE("(%p,%ld,%p)\n",hService,dwNumServiceArgs,lpServiceArgVectors); |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 620 | |
| 621 | if(dwNumServiceArgs) |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 622 | lpwstr = (LPWSTR*) HeapAlloc( GetProcessHeap(), 0, |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 623 | dwNumServiceArgs*sizeof(LPWSTR) ); |
| 624 | else |
| 625 | lpwstr = NULL; |
| 626 | |
| 627 | for(i=0; i<dwNumServiceArgs; i++) |
Matthew Davison | 60009b9 | 2003-01-23 23:07:38 +0000 | [diff] [blame] | 628 | { |
| 629 | RtlCreateUnicodeStringFromAsciiz (&usBuffer,lpServiceArgVectors[i]); |
| 630 | lpwstr[i]=usBuffer.Buffer; |
| 631 | } |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 632 | |
Andreas Mohr | 7fb732e | 1999-12-12 00:47:51 +0000 | [diff] [blame] | 633 | StartServiceW(hService, dwNumServiceArgs, (LPCWSTR *)lpwstr); |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 634 | |
| 635 | if(dwNumServiceArgs) |
| 636 | { |
| 637 | for(i=0; i<dwNumServiceArgs; i++) |
| 638 | HeapFree(GetProcessHeap(), 0, lpwstr[i]); |
| 639 | HeapFree(GetProcessHeap(), 0, lpwstr); |
| 640 | } |
| 641 | |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 642 | return TRUE; |
| 643 | } |
| 644 | |
| 645 | |
| 646 | /****************************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 647 | * StartServiceW [ADVAPI32.@] |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 648 | * Starts a service |
| 649 | * |
| 650 | * PARAMS |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 651 | * hService [I] Handle of service |
| 652 | * dwNumServiceArgs [I] Number of arguments |
| 653 | * lpServiceArgVectors [I] Address of array of argument string pointers |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 654 | * |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 655 | * NOTES |
| 656 | * |
| 657 | * NT implements this function using an obscure RPC call... |
| 658 | * |
| 659 | * Might need to do a "setenv SystemRoot \\WINNT" in your .cshrc |
| 660 | * to get things like %SystemRoot%\\System32\\service.exe to load. |
| 661 | * |
| 662 | * Will only work for shared address space. How should the service |
| 663 | * args be transferred when address spaces are separated? |
| 664 | * |
| 665 | * Can only start one service at a time. |
| 666 | * |
Francois Gouget | 3bb9a36 | 2001-10-22 19:04:32 +0000 | [diff] [blame] | 667 | * Has no concept of privilege. |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 668 | * |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 669 | * RETURNS STD |
| 670 | * |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 671 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 672 | BOOL WINAPI |
Patrik Stridvall | 4a73973 | 1999-07-04 11:01:21 +0000 | [diff] [blame] | 673 | StartServiceW( SC_HANDLE hService, DWORD dwNumServiceArgs, |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 674 | LPCWSTR *lpServiceArgVectors ) |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 675 | { |
Matthew Davison | 620323e | 2003-01-24 00:45:51 +0000 | [diff] [blame] | 676 | static const WCHAR _WaitServiceStartW[] = {'A','D','V','A','P','I','_','W', |
| 677 | 'a','i','t','S','e','r','v','i', |
| 678 | 'c','e','S','t','a','r','t',0}; |
| 679 | static const WCHAR _ImagePathW[] = {'I','m','a','g','e','P','a','t','h',0}; |
| 680 | |
| 681 | WCHAR path[MAX_PATH],str[MAX_PATH]; |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 682 | DWORD type,size; |
| 683 | long r; |
| 684 | HANDLE data,wait; |
| 685 | PROCESS_INFORMATION procinfo; |
Matthew Davison | 620323e | 2003-01-24 00:45:51 +0000 | [diff] [blame] | 686 | STARTUPINFOW startupinfo; |
Michael Stefaniuc | cbacde5 | 2002-10-25 19:17:33 +0000 | [diff] [blame] | 687 | TRACE("(%p,%ld,%p)\n",hService,dwNumServiceArgs, |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 688 | lpServiceArgVectors); |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 689 | |
Francois Gouget | 9591836 | 2003-06-18 19:45:22 +0000 | [diff] [blame] | 690 | size = sizeof(str); |
Matthew Davison | 620323e | 2003-01-24 00:45:51 +0000 | [diff] [blame] | 691 | r = RegQueryValueExW(hService, _ImagePathW, NULL, &type, (LPVOID)str, &size); |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 692 | if (r!=ERROR_SUCCESS) |
| 693 | return FALSE; |
Francois Gouget | 9591836 | 2003-06-18 19:45:22 +0000 | [diff] [blame] | 694 | ExpandEnvironmentStringsW(str,path,sizeof(path)); |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 695 | |
Matthew Davison | 620323e | 2003-01-24 00:45:51 +0000 | [diff] [blame] | 696 | TRACE("Starting service %s\n", debugstr_w(path) ); |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 697 | |
Matthew Davison | 620323e | 2003-01-24 00:45:51 +0000 | [diff] [blame] | 698 | data = CreateSemaphoreW(NULL,1,1,_ServiceStartDataW); |
Alexandre Julliard | 7375597 | 2002-07-31 19:26:03 +0000 | [diff] [blame] | 699 | if (!data) |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 700 | { |
Alexandre Julliard | b10dcfe | 2003-10-10 00:05:49 +0000 | [diff] [blame] | 701 | ERR("Couldn't create data semaphore\n"); |
| 702 | return FALSE; |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 703 | } |
Matthew Davison | 620323e | 2003-01-24 00:45:51 +0000 | [diff] [blame] | 704 | wait = CreateSemaphoreW(NULL,0,1,_WaitServiceStartW); |
Alexandre Julliard | b10dcfe | 2003-10-10 00:05:49 +0000 | [diff] [blame] | 705 | if (!wait) |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 706 | { |
Alexandre Julliard | b10dcfe | 2003-10-10 00:05:49 +0000 | [diff] [blame] | 707 | ERR("Couldn't create wait semaphore\n"); |
| 708 | return FALSE; |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 709 | } |
| 710 | |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 711 | /* |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 712 | * FIXME: lpServiceArgsVectors need to be stored and returned to |
| 713 | * the service when it calls StartServiceCtrlDispatcher |
| 714 | * |
| 715 | * Chuck these in a global (yuk) so we can pass them to |
| 716 | * another process - address space separation will break this. |
| 717 | */ |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 718 | |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 719 | r = WaitForSingleObject(data,INFINITE); |
| 720 | |
| 721 | if( r == WAIT_FAILED) |
| 722 | return FALSE; |
| 723 | |
Andreas Mohr | 18a9d74 | 2001-01-17 21:52:42 +0000 | [diff] [blame] | 724 | FIXME("problematic because of address space separation.\n"); |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 725 | start_dwNumServiceArgs = dwNumServiceArgs; |
Andreas Mohr | 7fb732e | 1999-12-12 00:47:51 +0000 | [diff] [blame] | 726 | start_lpServiceArgVectors = (LPWSTR *)lpServiceArgVectors; |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 727 | |
Matthew Davison | 620323e | 2003-01-24 00:45:51 +0000 | [diff] [blame] | 728 | ZeroMemory(&startupinfo,sizeof(STARTUPINFOW)); |
| 729 | startupinfo.cb = sizeof(STARTUPINFOW); |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 730 | |
Matthew Davison | 620323e | 2003-01-24 00:45:51 +0000 | [diff] [blame] | 731 | r = CreateProcessW(path, |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 732 | NULL, |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 733 | NULL, /* process security attribs */ |
| 734 | NULL, /* thread security attribs */ |
| 735 | FALSE, /* inherit handles */ |
| 736 | 0, /* creation flags */ |
| 737 | NULL, /* environment */ |
| 738 | NULL, /* current directory */ |
| 739 | &startupinfo, /* startup info */ |
| 740 | &procinfo); /* process info */ |
| 741 | |
| 742 | if(r == FALSE) |
| 743 | { |
| 744 | ERR("Couldn't start process\n"); |
| 745 | /* ReleaseSemaphore(data, 1, NULL); |
| 746 | return FALSE; */ |
| 747 | } |
| 748 | |
| 749 | /* docs for StartServiceCtrlDispatcher say this should be 30 sec */ |
| 750 | r = WaitForSingleObject(wait,30000); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 751 | |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 752 | ReleaseSemaphore(data, 1, NULL); |
| 753 | |
| 754 | if( r == WAIT_FAILED) |
| 755 | return FALSE; |
| 756 | |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 757 | return TRUE; |
| 758 | } |
| 759 | |
| 760 | /****************************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 761 | * QueryServiceStatus [ADVAPI32.@] |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 762 | * |
| 763 | * PARAMS |
| 764 | * hService [] |
| 765 | * lpservicestatus [] |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 766 | * |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 767 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 768 | BOOL WINAPI |
Patrik Stridvall | 4a73973 | 1999-07-04 11:01:21 +0000 | [diff] [blame] | 769 | QueryServiceStatus( SC_HANDLE hService, LPSERVICE_STATUS lpservicestatus ) |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 770 | { |
Michael McCormack | 75a8413 | 1999-11-21 00:58:14 +0000 | [diff] [blame] | 771 | LONG r; |
| 772 | DWORD type, val, size; |
| 773 | |
Michael Stefaniuc | cbacde5 | 2002-10-25 19:17:33 +0000 | [diff] [blame] | 774 | FIXME("(%p,%p) partial\n",hService,lpservicestatus); |
Michael McCormack | 75a8413 | 1999-11-21 00:58:14 +0000 | [diff] [blame] | 775 | |
| 776 | /* read the service type from the registry */ |
Francois Gouget | 9591836 | 2003-06-18 19:45:22 +0000 | [diff] [blame] | 777 | size = sizeof(val); |
Michael McCormack | 75a8413 | 1999-11-21 00:58:14 +0000 | [diff] [blame] | 778 | r = RegQueryValueExA(hService, "Type", NULL, &type, (LPBYTE)&val, &size); |
| 779 | if(type!=REG_DWORD) |
| 780 | { |
| 781 | ERR("invalid Type\n"); |
| 782 | return FALSE; |
| 783 | } |
| 784 | lpservicestatus->dwServiceType = val; |
Michael McCormack | 75a8413 | 1999-11-21 00:58:14 +0000 | [diff] [blame] | 785 | /* FIXME: how are these determined or read from the registry? */ |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 786 | /* SERVICE: unavailable=0, stopped=1, starting=2, running=3? */; |
| 787 | lpservicestatus->dwCurrentState = 1; |
Michael McCormack | 75a8413 | 1999-11-21 00:58:14 +0000 | [diff] [blame] | 788 | lpservicestatus->dwControlsAccepted = 0; |
| 789 | lpservicestatus->dwWin32ExitCode = NO_ERROR; |
| 790 | lpservicestatus->dwServiceSpecificExitCode = 0; |
| 791 | lpservicestatus->dwCheckPoint = 0; |
| 792 | lpservicestatus->dwWaitHint = 0; |
| 793 | |
| 794 | return TRUE; |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 795 | } |
Steve Lustbader | f1e1fd0 | 2002-11-25 20:50:53 +0000 | [diff] [blame] | 796 | |
| 797 | /****************************************************************************** |
| 798 | * QueryServiceStatusEx [ADVAPI32.@] |
| 799 | * |
| 800 | * PARAMS |
| 801 | * hService [handle to service] |
| 802 | * InfoLevel [information level] |
| 803 | * lpBuffer [buffer] |
| 804 | * cbBufSize [size of buffer] |
| 805 | * pcbBytesNeeded [bytes needed] |
| 806 | */ |
| 807 | BOOL WINAPI QueryServiceStatusEx(SC_HANDLE hService, SC_STATUS_TYPE InfoLevel, |
| 808 | LPBYTE lpBuffer, DWORD cbBufSize, |
| 809 | LPDWORD pcbBytesNeeded) |
| 810 | { |
| 811 | FIXME("stub\n"); |
| 812 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED); |
| 813 | return FALSE; |
| 814 | } |
Mike McCormack | 9b513ad | 2003-12-02 03:48:53 +0000 | [diff] [blame^] | 815 | |
| 816 | /****************************************************************************** |
| 817 | * QueryServiceConfigA [ADVAPI32.@] |
| 818 | */ |
| 819 | BOOL WINAPI |
| 820 | QueryServiceConfigA( SC_HANDLE hService, |
| 821 | LPQUERY_SERVICE_CONFIGA lpServiceConfig, |
| 822 | DWORD cbBufSize, LPDWORD pcbBytesNeeded) |
| 823 | { |
| 824 | FIXME("%p %p %ld %p\n", hService, lpServiceConfig, |
| 825 | cbBufSize, pcbBytesNeeded); |
| 826 | return FALSE; |
| 827 | } |
| 828 | |
| 829 | /****************************************************************************** |
| 830 | * QueryServiceConfigW [ADVAPI32.@] |
| 831 | */ |
| 832 | BOOL WINAPI |
| 833 | QueryServiceConfigW( SC_HANDLE hService, |
| 834 | LPQUERY_SERVICE_CONFIGW lpServiceConfig, |
| 835 | DWORD cbBufSize, LPDWORD pcbBytesNeeded) |
| 836 | { |
| 837 | const WCHAR szDisplayName[] = { |
| 838 | 'D','i','s','p','l','a','y','N','a','m','e', 0 }; |
| 839 | const WCHAR szType[] = {'T','y','p','e',0}; |
| 840 | const WCHAR szStart[] = {'S','t','a','r','t',0}; |
| 841 | const WCHAR szError[] = { |
| 842 | 'E','r','r','o','r','C','o','n','t','r','o','l', 0}; |
| 843 | const WCHAR szImagePath[] = {'I','m','a','g','e','P','a','t','h',0}; |
| 844 | const WCHAR szGroup[] = {'G','r','o','u','p',0}; |
| 845 | const WCHAR szDependencies[] = { |
| 846 | 'D','e','p','e','n','d','e','n','c','i','e','s',0}; |
| 847 | LONG r; |
| 848 | DWORD type, val, sz, total, n; |
| 849 | LPBYTE p; |
| 850 | |
| 851 | TRACE("%p %p %ld %p\n", hService, lpServiceConfig, |
| 852 | cbBufSize, pcbBytesNeeded); |
| 853 | |
| 854 | /* calculate the size required first */ |
| 855 | total = sizeof (QUERY_SERVICE_CONFIGW); |
| 856 | |
| 857 | sz = 0; |
| 858 | r = RegQueryValueExW( hService, szImagePath, 0, &type, NULL, &sz ); |
| 859 | if( ( r == ERROR_SUCCESS ) && ( type == REG_SZ ) ) |
| 860 | total += sz; |
| 861 | |
| 862 | sz = 0; |
| 863 | r = RegQueryValueExW( hService, szGroup, 0, &type, NULL, &sz ); |
| 864 | if( ( r == ERROR_SUCCESS ) && ( type == REG_SZ ) ) |
| 865 | total += sz; |
| 866 | |
| 867 | sz = 0; |
| 868 | r = RegQueryValueExW( hService, szDependencies, 0, &type, NULL, &sz ); |
| 869 | if( ( r == ERROR_SUCCESS ) && ( type == REG_MULTI_SZ ) ) |
| 870 | total += sz; |
| 871 | |
| 872 | sz = 0; |
| 873 | r = RegQueryValueExW( hService, szStart, 0, &type, NULL, &sz ); |
| 874 | if( ( r == ERROR_SUCCESS ) && ( type == REG_SZ ) ) |
| 875 | total += sz; |
| 876 | |
| 877 | sz = 0; |
| 878 | r = RegQueryValueExW( hService, szDisplayName, 0, &type, NULL, &sz ); |
| 879 | if( ( r == ERROR_SUCCESS ) && ( type == REG_SZ ) ) |
| 880 | total += sz; |
| 881 | |
| 882 | /* if there's not enough memory, return an error */ |
| 883 | if( total > *pcbBytesNeeded ) |
| 884 | { |
| 885 | *pcbBytesNeeded = total; |
| 886 | SetLastError( ERROR_INSUFFICIENT_BUFFER ); |
| 887 | return FALSE; |
| 888 | } |
| 889 | |
| 890 | *pcbBytesNeeded = total; |
| 891 | ZeroMemory( lpServiceConfig, total ); |
| 892 | |
| 893 | sz = sizeof val; |
| 894 | r = RegQueryValueExW( hService, szType, 0, &type, (LPBYTE)&val, &sz ); |
| 895 | if( ( r == ERROR_SUCCESS ) || ( type == REG_DWORD ) ) |
| 896 | lpServiceConfig->dwServiceType = val; |
| 897 | |
| 898 | sz = sizeof val; |
| 899 | r = RegQueryValueExW( hService, szStart, 0, &type, (LPBYTE)&val, &sz ); |
| 900 | if( ( r == ERROR_SUCCESS ) || ( type == REG_DWORD ) ) |
| 901 | lpServiceConfig->dwStartType = val; |
| 902 | |
| 903 | sz = sizeof val; |
| 904 | r = RegQueryValueExW( hService, szError, 0, &type, (LPBYTE)&val, &sz ); |
| 905 | if( ( r == ERROR_SUCCESS ) || ( type == REG_DWORD ) ) |
| 906 | lpServiceConfig->dwErrorControl = val; |
| 907 | |
| 908 | /* now do the strings */ |
| 909 | p = (LPBYTE) &lpServiceConfig[1]; |
| 910 | n = total - sizeof (QUERY_SERVICE_CONFIGW); |
| 911 | |
| 912 | sz = n; |
| 913 | r = RegQueryValueExW( hService, szImagePath, 0, &type, p, &sz ); |
| 914 | if( ( r == ERROR_SUCCESS ) || ( type == REG_SZ ) ) |
| 915 | { |
| 916 | lpServiceConfig->lpBinaryPathName = (LPWSTR) p; |
| 917 | p += sz; |
| 918 | n -= sz; |
| 919 | } |
| 920 | |
| 921 | sz = n; |
| 922 | r = RegQueryValueExW( hService, szGroup, 0, &type, p, &sz ); |
| 923 | if( ( r == ERROR_SUCCESS ) || ( type == REG_SZ ) ) |
| 924 | { |
| 925 | lpServiceConfig->lpLoadOrderGroup = (LPWSTR) p; |
| 926 | p += sz; |
| 927 | n -= sz; |
| 928 | } |
| 929 | |
| 930 | sz = n; |
| 931 | r = RegQueryValueExW( hService, szDependencies, 0, &type, p, &sz ); |
| 932 | if( ( r == ERROR_SUCCESS ) || ( type == REG_SZ ) ) |
| 933 | { |
| 934 | lpServiceConfig->lpDependencies = (LPWSTR) p; |
| 935 | p += sz; |
| 936 | n -= sz; |
| 937 | } |
| 938 | |
| 939 | if( n < 0 ) |
| 940 | ERR("Buffer overflow!\n"); |
| 941 | |
| 942 | TRACE("Image path = %s\n", debugstr_w(lpServiceConfig->lpBinaryPathName) ); |
| 943 | TRACE("Group = %s\n", debugstr_w(lpServiceConfig->lpLoadOrderGroup) ); |
| 944 | |
| 945 | return TRUE; |
| 946 | } |
| 947 | |
| 948 | /****************************************************************************** |
| 949 | * ChangeServiceConfigW [ADVAPI32.@] |
| 950 | */ |
| 951 | BOOL WINAPI ChangeServiceConfigW( SC_HANDLE hService, DWORD dwServiceType, |
| 952 | DWORD dwStartType, DWORD dwErrorControl, LPCWSTR lpBinaryPathName, |
| 953 | LPCWSTR lpLoadOrderGroup, LPDWORD lpdwTagId, LPCWSTR lpDependencies, |
| 954 | LPCWSTR lpServiceStartName, LPCWSTR lpPassword, LPCWSTR lpDisplayName) |
| 955 | { |
| 956 | FIXME("%p %ld %ld %ld %s %s %p %p %s %s %s\n", |
| 957 | hService, dwServiceType, dwStartType, dwErrorControl, |
| 958 | debugstr_w(lpBinaryPathName), debugstr_w(lpLoadOrderGroup), |
| 959 | lpdwTagId, lpDependencies, debugstr_w(lpServiceStartName), |
| 960 | debugstr_w(lpPassword), debugstr_w(lpDisplayName) ); |
| 961 | return TRUE; |
| 962 | } |
| 963 | |
| 964 | /****************************************************************************** |
| 965 | * ChangeServiceConfigA [ADVAPI32.@] |
| 966 | */ |
| 967 | BOOL WINAPI ChangeServiceConfigA( SC_HANDLE hService, DWORD dwServiceType, |
| 968 | DWORD dwStartType, DWORD dwErrorControl, LPCSTR lpBinaryPathName, |
| 969 | LPCSTR lpLoadOrderGroup, LPDWORD lpdwTagId, LPCSTR lpDependencies, |
| 970 | LPCSTR lpServiceStartName, LPCSTR lpPassword, LPCSTR lpDisplayName) |
| 971 | { |
| 972 | FIXME("%p %ld %ld %ld %s %s %p %p %s %s %s\n", |
| 973 | hService, dwServiceType, dwStartType, dwErrorControl, |
| 974 | debugstr_a(lpBinaryPathName), debugstr_a(lpLoadOrderGroup), |
| 975 | lpdwTagId, lpDependencies, debugstr_a(lpServiceStartName), |
| 976 | debugstr_a(lpPassword), debugstr_a(lpDisplayName) ); |
| 977 | return TRUE; |
| 978 | } |