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