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.@] |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 243 | */ |
Patrik Stridvall | 4a73973 | 1999-07-04 11:01:21 +0000 | [diff] [blame] | 244 | SC_HANDLE WINAPI |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 245 | OpenSCManagerA( LPCSTR lpMachineName, LPCSTR lpDatabaseName, |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 246 | DWORD dwDesiredAccess ) |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 247 | { |
Matthew Davison | 6f2a071 | 2003-01-20 23:23:12 +0000 | [diff] [blame] | 248 | UNICODE_STRING lpMachineNameW; |
| 249 | UNICODE_STRING lpDatabaseNameW; |
| 250 | SC_HANDLE ret; |
| 251 | |
| 252 | RtlCreateUnicodeStringFromAsciiz (&lpMachineNameW,lpMachineName); |
| 253 | RtlCreateUnicodeStringFromAsciiz (&lpDatabaseNameW,lpDatabaseName); |
| 254 | ret = OpenSCManagerW(lpMachineNameW.Buffer,lpDatabaseNameW.Buffer, dwDesiredAccess); |
| 255 | RtlFreeUnicodeString(&lpDatabaseNameW); |
| 256 | RtlFreeUnicodeString(&lpMachineNameW); |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 257 | return ret; |
| 258 | } |
| 259 | |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 260 | /****************************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 261 | * OpenSCManagerW [ADVAPI32.@] |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 262 | * Establishes a connection to the service control manager and opens database |
| 263 | * |
| 264 | * NOTES |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 265 | * This should return a SC_HANDLE |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 266 | * |
| 267 | * PARAMS |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 268 | * lpMachineName [I] Pointer to machine name string |
| 269 | * lpDatabaseName [I] Pointer to database name string |
| 270 | * dwDesiredAccess [I] Type of access |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 271 | * |
| 272 | * RETURNS |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 273 | * Success: Handle to service control manager database |
| 274 | * Failure: NULL |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 275 | */ |
Patrik Stridvall | 4a73973 | 1999-07-04 11:01:21 +0000 | [diff] [blame] | 276 | SC_HANDLE WINAPI |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 277 | OpenSCManagerW( LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 278 | DWORD dwDesiredAccess ) |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 279 | { |
Mike McCormack | 9b513ad | 2003-12-02 03:48:53 +0000 | [diff] [blame] | 280 | HKEY hReg, hKey = NULL; |
Michael McCormack | 75a8413 | 1999-11-21 00:58:14 +0000 | [diff] [blame] | 281 | LONG r; |
| 282 | |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 283 | TRACE("(%s,%s,0x%08lx)\n", debugstr_w(lpMachineName), |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 284 | debugstr_w(lpDatabaseName), dwDesiredAccess); |
Michael McCormack | 75a8413 | 1999-11-21 00:58:14 +0000 | [diff] [blame] | 285 | |
| 286 | /* |
| 287 | * FIXME: what is lpDatabaseName? |
| 288 | * It should be set to "SERVICES_ACTIVE_DATABASE" according to |
| 289 | * docs, but what if it isn't? |
| 290 | */ |
| 291 | |
Mike McCormack | 9b513ad | 2003-12-02 03:48:53 +0000 | [diff] [blame] | 292 | r = RegConnectRegistryW(lpMachineName,HKEY_LOCAL_MACHINE,&hReg); |
| 293 | if (r==ERROR_SUCCESS) |
| 294 | { |
Aric Stewart | 3dc71b6 | 2003-12-13 03:25:37 +0000 | [diff] [blame] | 295 | r = RegOpenKeyExW(hReg, szServiceManagerKey,0, dwDesiredAccess, &hKey ); |
Mike McCormack | 9b513ad | 2003-12-02 03:48:53 +0000 | [diff] [blame] | 296 | RegCloseKey( hReg ); |
| 297 | } |
Michael McCormack | 75a8413 | 1999-11-21 00:58:14 +0000 | [diff] [blame] | 298 | |
Mike McCormack | 9b513ad | 2003-12-02 03:48:53 +0000 | [diff] [blame] | 299 | TRACE("returning %p\n", hKey); |
Michael McCormack | 75a8413 | 1999-11-21 00:58:14 +0000 | [diff] [blame] | 300 | |
| 301 | return hKey; |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 305 | /****************************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 306 | * AllocateLocallyUniqueId [ADVAPI32.@] |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 307 | * |
| 308 | * PARAMS |
| 309 | * lpluid [] |
| 310 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 311 | BOOL WINAPI |
Juergen Schmied | 1ed51af | 1999-02-12 17:47:07 +0000 | [diff] [blame] | 312 | AllocateLocallyUniqueId( PLUID lpluid ) |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 313 | { |
Francois Gouget | ea31cf0 | 2001-11-20 18:52:20 +0000 | [diff] [blame] | 314 | lpluid->LowPart = time(NULL); |
| 315 | lpluid->HighPart = 0; |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 316 | return TRUE; |
| 317 | } |
| 318 | |
| 319 | |
| 320 | /****************************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 321 | * ControlService [ADVAPI32.@] |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 322 | * Sends a control code to a Win32-based service. |
| 323 | * |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 324 | * PARAMS |
| 325 | * hService [] |
| 326 | * dwControl [] |
| 327 | * lpServiceStatus [] |
| 328 | * |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 329 | * RETURNS STD |
| 330 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 331 | BOOL WINAPI |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 332 | ControlService( SC_HANDLE hService, DWORD dwControl, |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 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.@] |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 342 | * Close handle to service or service control manager |
| 343 | * |
| 344 | * PARAMS |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 345 | * hSCObject [I] Handle to service or service control manager database |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 346 | * |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 347 | * RETURNS STD |
| 348 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 349 | BOOL WINAPI |
Patrik Stridvall | 4a73973 | 1999-07-04 11:01:21 +0000 | [diff] [blame] | 350 | CloseServiceHandle( SC_HANDLE hSCObject ) |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 351 | { |
Michael Stefaniuc | cbacde5 | 2002-10-25 19:17:33 +0000 | [diff] [blame] | 352 | TRACE("(%p)\n", hSCObject); |
Michael McCormack | 75a8413 | 1999-11-21 00:58:14 +0000 | [diff] [blame] | 353 | |
| 354 | RegCloseKey(hSCObject); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 355 | |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 356 | return TRUE; |
| 357 | } |
| 358 | |
| 359 | |
| 360 | /****************************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 361 | * OpenServiceA [ADVAPI32.@] |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 362 | */ |
Patrik Stridvall | 4a73973 | 1999-07-04 11:01:21 +0000 | [diff] [blame] | 363 | SC_HANDLE WINAPI |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 364 | OpenServiceA( SC_HANDLE hSCManager, LPCSTR lpServiceName, |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 365 | DWORD dwDesiredAccess ) |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 366 | { |
Matthew Davison | 6f2a071 | 2003-01-20 23:23:12 +0000 | [diff] [blame] | 367 | UNICODE_STRING lpServiceNameW; |
François Gouget | 97ad5a7 | 2001-01-02 20:20:34 +0000 | [diff] [blame] | 368 | SC_HANDLE ret; |
Matthew Davison | 6f2a071 | 2003-01-20 23:23:12 +0000 | [diff] [blame] | 369 | RtlCreateUnicodeStringFromAsciiz (&lpServiceNameW,lpServiceName); |
Michael McCormack | 75a8413 | 1999-11-21 00:58:14 +0000 | [diff] [blame] | 370 | if(lpServiceName) |
| 371 | TRACE("Request for service %s\n",lpServiceName); |
| 372 | else |
| 373 | return FALSE; |
Matthew Davison | 6f2a071 | 2003-01-20 23:23:12 +0000 | [diff] [blame] | 374 | ret = OpenServiceW( hSCManager, lpServiceNameW.Buffer, dwDesiredAccess); |
| 375 | RtlFreeUnicodeString(&lpServiceNameW); |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 376 | return ret; |
| 377 | } |
| 378 | |
| 379 | |
| 380 | /****************************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 381 | * OpenServiceW [ADVAPI32.@] |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 382 | * Opens a handle to an existing service |
| 383 | * |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 384 | * PARAMS |
| 385 | * hSCManager [] |
| 386 | * lpServiceName [] |
| 387 | * dwDesiredAccess [] |
| 388 | * |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 389 | * RETURNS |
| 390 | * Success: Handle to the service |
| 391 | * Failure: NULL |
| 392 | */ |
Patrik Stridvall | 4a73973 | 1999-07-04 11:01:21 +0000 | [diff] [blame] | 393 | SC_HANDLE WINAPI |
| 394 | OpenServiceW(SC_HANDLE hSCManager, LPCWSTR lpServiceName, |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 395 | DWORD dwDesiredAccess) |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 396 | { |
Michael McCormack | 75a8413 | 1999-11-21 00:58:14 +0000 | [diff] [blame] | 397 | HKEY hKey; |
| 398 | long r; |
| 399 | |
Michael Stefaniuc | cbacde5 | 2002-10-25 19:17:33 +0000 | [diff] [blame] | 400 | TRACE("(%p,%p,%ld)\n",hSCManager, lpServiceName, |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 401 | dwDesiredAccess); |
Michael McCormack | 75a8413 | 1999-11-21 00:58:14 +0000 | [diff] [blame] | 402 | |
Alexandre Julliard | bea945e | 2004-04-12 22:18:39 +0000 | [diff] [blame^] | 403 | r = RegOpenKeyExW(hSCManager, lpServiceName, 0, KEY_ALL_ACCESS, &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, |
Aric Stewart | 3dc71b6 | 2003-12-13 03:25:37 +0000 | [diff] [blame] | 439 | REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dp); |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 440 | if (r!=ERROR_SUCCESS) |
| 441 | return 0; |
Aric Stewart | 3dc71b6 | 2003-12-13 03:25:37 +0000 | [diff] [blame] | 442 | |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 443 | if (dp != REG_CREATED_NEW_KEY) |
| 444 | return 0; |
| 445 | |
| 446 | if(lpDisplayName) |
| 447 | { |
Mike McCormack | 9b513ad | 2003-12-02 03:48:53 +0000 | [diff] [blame] | 448 | r = RegSetValueExW(hKey, szDisplayName, 0, REG_SZ, (LPBYTE)lpDisplayName, |
| 449 | (strlenW(lpDisplayName)+1)*sizeof(WCHAR) ); |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 450 | if (r!=ERROR_SUCCESS) |
| 451 | return 0; |
| 452 | } |
| 453 | |
Mike McCormack | 9b513ad | 2003-12-02 03:48:53 +0000 | [diff] [blame] | 454 | r = RegSetValueExW(hKey, szType, 0, REG_DWORD, (LPVOID)&dwServiceType, sizeof (DWORD) ); |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 455 | if (r!=ERROR_SUCCESS) |
| 456 | return 0; |
| 457 | |
Mike McCormack | 9b513ad | 2003-12-02 03:48:53 +0000 | [diff] [blame] | 458 | r = RegSetValueExW(hKey, szStart, 0, REG_DWORD, (LPVOID)&dwStartType, 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, szError, 0, REG_DWORD, |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 463 | (LPVOID)&dwErrorControl, sizeof (DWORD) ); |
| 464 | if (r!=ERROR_SUCCESS) |
| 465 | return 0; |
| 466 | |
| 467 | if(lpBinaryPathName) |
| 468 | { |
Mike McCormack | 9b513ad | 2003-12-02 03:48:53 +0000 | [diff] [blame] | 469 | r = RegSetValueExW(hKey, szImagePath, 0, REG_SZ, (LPBYTE)lpBinaryPathName, |
| 470 | (strlenW(lpBinaryPathName)+1)*sizeof(WCHAR) ); |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 471 | if (r!=ERROR_SUCCESS) |
| 472 | return 0; |
| 473 | } |
| 474 | |
| 475 | if(lpLoadOrderGroup) |
| 476 | { |
Mike McCormack | 9b513ad | 2003-12-02 03:48:53 +0000 | [diff] [blame] | 477 | r = RegSetValueExW(hKey, szGroup, 0, REG_SZ, (LPBYTE)lpLoadOrderGroup, |
| 478 | (strlenW(lpLoadOrderGroup)+1)*sizeof(WCHAR) ); |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 479 | if (r!=ERROR_SUCCESS) |
| 480 | return 0; |
| 481 | } |
| 482 | |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 483 | if(lpDependencies) |
| 484 | { |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 485 | DWORD len = 0; |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 486 | |
| 487 | /* determine the length of a double null terminated multi string */ |
| 488 | do { |
Mike McCormack | 9b513ad | 2003-12-02 03:48:53 +0000 | [diff] [blame] | 489 | len += (strlenW(&lpDependencies[len])+1); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 490 | } while (lpDependencies[len++]); |
| 491 | |
Mike McCormack | 9b513ad | 2003-12-02 03:48:53 +0000 | [diff] [blame] | 492 | r = RegSetValueExW(hKey, szDependencies, 0, REG_MULTI_SZ, |
| 493 | (LPBYTE)lpDependencies, len ); |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 494 | if (r!=ERROR_SUCCESS) |
| 495 | return 0; |
| 496 | } |
| 497 | |
| 498 | if(lpPassword) |
| 499 | { |
| 500 | FIXME("Don't know how to add a Password for a service.\n"); |
| 501 | } |
| 502 | |
| 503 | if(lpServiceStartName) |
| 504 | { |
| 505 | FIXME("Don't know how to add a ServiceStartName for a service.\n"); |
| 506 | } |
| 507 | |
| 508 | return hKey; |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | |
Mike McCormack | 9b513ad | 2003-12-02 03:48:53 +0000 | [diff] [blame] | 512 | static inline LPWSTR SERV_dup( LPCSTR str ) |
| 513 | { |
| 514 | UINT len; |
| 515 | LPWSTR wstr; |
| 516 | |
| 517 | if( !str ) |
| 518 | return NULL; |
| 519 | len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 ); |
| 520 | wstr = HeapAlloc( GetProcessHeap(), 0, len*sizeof (WCHAR) ); |
| 521 | MultiByteToWideChar( CP_ACP, 0, str, -1, wstr, len ); |
| 522 | return wstr; |
| 523 | } |
| 524 | |
| 525 | static inline LPWSTR SERV_dupmulti( LPCSTR str ) |
| 526 | { |
| 527 | UINT len = 0, n = 0; |
| 528 | LPWSTR wstr; |
| 529 | |
Huw Davies | 28c2ea0 | 2003-12-11 04:26:20 +0000 | [diff] [blame] | 530 | if( !str ) |
| 531 | return NULL; |
Mike McCormack | 9b513ad | 2003-12-02 03:48:53 +0000 | [diff] [blame] | 532 | do { |
| 533 | len += MultiByteToWideChar( CP_ACP, 0, &str[n], -1, NULL, 0 ); |
| 534 | n += (strlen( &str[n] ) + 1); |
| 535 | } while (str[n]); |
| 536 | len++; |
| 537 | n++; |
| 538 | |
| 539 | wstr = HeapAlloc( GetProcessHeap(), 0, len*sizeof (WCHAR) ); |
| 540 | MultiByteToWideChar( CP_ACP, 0, str, n, wstr, len ); |
| 541 | return wstr; |
| 542 | } |
| 543 | |
| 544 | static inline VOID SERV_free( LPWSTR wstr ) |
| 545 | { |
| 546 | HeapFree( GetProcessHeap(), 0, wstr ); |
| 547 | } |
| 548 | |
| 549 | /****************************************************************************** |
| 550 | * CreateServiceA [ADVAPI32.@] |
| 551 | */ |
| 552 | SC_HANDLE WINAPI |
| 553 | CreateServiceA( SC_HANDLE hSCManager, LPCSTR lpServiceName, |
| 554 | LPCSTR lpDisplayName, DWORD dwDesiredAccess, |
| 555 | DWORD dwServiceType, DWORD dwStartType, |
| 556 | DWORD dwErrorControl, LPCSTR lpBinaryPathName, |
| 557 | LPCSTR lpLoadOrderGroup, LPDWORD lpdwTagId, |
| 558 | LPCSTR lpDependencies, LPCSTR lpServiceStartName, |
| 559 | LPCSTR lpPassword ) |
| 560 | { |
| 561 | LPWSTR lpServiceNameW, lpDisplayNameW, lpBinaryPathNameW, |
| 562 | lpLoadOrderGroupW, lpDependenciesW, lpServiceStartNameW, lpPasswordW; |
| 563 | SC_HANDLE r; |
| 564 | |
| 565 | TRACE("%p %s %s\n", hSCManager, |
| 566 | debugstr_a(lpServiceName), debugstr_a(lpDisplayName)); |
| 567 | |
| 568 | lpServiceNameW = SERV_dup( lpServiceName ); |
| 569 | lpDisplayNameW = SERV_dup( lpDisplayName ); |
| 570 | lpBinaryPathNameW = SERV_dup( lpBinaryPathName ); |
| 571 | lpLoadOrderGroupW = SERV_dup( lpLoadOrderGroup ); |
| 572 | lpDependenciesW = SERV_dupmulti( lpDependencies ); |
| 573 | lpServiceStartNameW = SERV_dup( lpServiceStartName ); |
| 574 | lpPasswordW = SERV_dup( lpPassword ); |
| 575 | |
| 576 | r = CreateServiceW( hSCManager, lpServiceNameW, lpDisplayNameW, |
| 577 | dwDesiredAccess, dwServiceType, dwStartType, dwErrorControl, |
| 578 | lpBinaryPathNameW, lpLoadOrderGroupW, lpdwTagId, |
| 579 | lpDependenciesW, lpServiceStartNameW, lpPasswordW ); |
| 580 | |
| 581 | SERV_free( lpServiceNameW ); |
| 582 | SERV_free( lpDisplayNameW ); |
| 583 | SERV_free( lpBinaryPathNameW ); |
| 584 | SERV_free( lpLoadOrderGroupW ); |
| 585 | SERV_free( lpDependenciesW ); |
| 586 | SERV_free( lpServiceStartNameW ); |
| 587 | SERV_free( lpPasswordW ); |
| 588 | |
| 589 | return r; |
| 590 | } |
| 591 | |
| 592 | |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 593 | /****************************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 594 | * DeleteService [ADVAPI32.@] |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 595 | * |
| 596 | * PARAMS |
| 597 | * hService [I] Handle to service |
| 598 | * |
| 599 | * RETURNS STD |
| 600 | * |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 601 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 602 | BOOL WINAPI |
Patrik Stridvall | 4a73973 | 1999-07-04 11:01:21 +0000 | [diff] [blame] | 603 | DeleteService( SC_HANDLE hService ) |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 604 | { |
Aric Stewart | 3dc71b6 | 2003-12-13 03:25:37 +0000 | [diff] [blame] | 605 | WCHAR valname[MAX_PATH+1]; |
| 606 | INT index = 0; |
| 607 | LONG rc; |
| 608 | DWORD value = 0x1; |
| 609 | DWORD size; |
| 610 | HKEY hKey; |
| 611 | |
| 612 | static const WCHAR szDeleted[] = {'D','e','l','e','t','e','d',0}; |
| 613 | |
Michael Stefaniuc | cbacde5 | 2002-10-25 19:17:33 +0000 | [diff] [blame] | 614 | FIXME("(%p): stub\n",hService); |
Aric Stewart | 3dc71b6 | 2003-12-13 03:25:37 +0000 | [diff] [blame] | 615 | |
| 616 | size = MAX_PATH+1; |
| 617 | /* Clean out the values */ |
| 618 | rc = RegEnumValueW(hService, index, valname,&size,0,0,0,0); |
| 619 | while (rc == ERROR_SUCCESS) |
| 620 | { |
| 621 | RegDeleteValueW(hService,valname); |
| 622 | index++; |
| 623 | size = MAX_PATH+1; |
| 624 | rc = RegEnumValueW(hService, index, valname, &size,0,0,0,0); |
| 625 | } |
| 626 | |
| 627 | /* tag for deletion */ |
| 628 | RegSetValueExW(hService, szDeleted, 0, REG_DWORD, (LPVOID)&value, |
| 629 | sizeof (DWORD) ); |
| 630 | |
| 631 | RegCloseKey(hService); |
| 632 | |
| 633 | /* find and delete the key */ |
| 634 | rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, szServiceManagerKey,0, |
| 635 | KEY_ALL_ACCESS, &hKey ); |
| 636 | index = 0; |
| 637 | size = MAX_PATH+1; |
| 638 | rc = RegEnumKeyExW(hKey,0, valname, &size, 0, 0, 0, 0); |
| 639 | while (rc == ERROR_SUCCESS) |
| 640 | { |
| 641 | HKEY checking; |
| 642 | rc = RegOpenKeyExW(hKey,valname,0,KEY_ALL_ACCESS,&checking); |
| 643 | if (rc == ERROR_SUCCESS) |
| 644 | { |
| 645 | DWORD deleted = 0; |
| 646 | DWORD size = sizeof(DWORD); |
| 647 | rc = RegQueryValueExW(checking, szDeleted , NULL, NULL, |
| 648 | (LPVOID)&deleted, &size); |
| 649 | if (deleted) |
| 650 | { |
| 651 | RegDeleteValueW(checking,szDeleted); |
| 652 | RegDeleteKeyW(hKey,valname); |
| 653 | } |
| 654 | else |
| 655 | index ++; |
| 656 | RegCloseKey(checking); |
| 657 | } |
| 658 | size = MAX_PATH+1; |
| 659 | rc = RegEnumKeyExW(hKey, index, valname, &size, 0, 0, 0, 0); |
| 660 | } |
| 661 | RegCloseKey(hKey); |
| 662 | |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 663 | return TRUE; |
| 664 | } |
| 665 | |
| 666 | |
| 667 | /****************************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 668 | * StartServiceA [ADVAPI32.@] |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 669 | * |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 670 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 671 | BOOL WINAPI |
Patrik Stridvall | 4a73973 | 1999-07-04 11:01:21 +0000 | [diff] [blame] | 672 | StartServiceA( SC_HANDLE hService, DWORD dwNumServiceArgs, |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 673 | LPCSTR *lpServiceArgVectors ) |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 674 | { |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 675 | LPWSTR *lpwstr=NULL; |
Matthew Davison | 60009b9 | 2003-01-23 23:07:38 +0000 | [diff] [blame] | 676 | UNICODE_STRING usBuffer; |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 677 | int i; |
| 678 | |
Michael Stefaniuc | cbacde5 | 2002-10-25 19:17:33 +0000 | [diff] [blame] | 679 | TRACE("(%p,%ld,%p)\n",hService,dwNumServiceArgs,lpServiceArgVectors); |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 680 | |
| 681 | if(dwNumServiceArgs) |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 682 | lpwstr = (LPWSTR*) HeapAlloc( GetProcessHeap(), 0, |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 683 | dwNumServiceArgs*sizeof(LPWSTR) ); |
| 684 | else |
| 685 | lpwstr = NULL; |
| 686 | |
| 687 | for(i=0; i<dwNumServiceArgs; i++) |
Matthew Davison | 60009b9 | 2003-01-23 23:07:38 +0000 | [diff] [blame] | 688 | { |
| 689 | RtlCreateUnicodeStringFromAsciiz (&usBuffer,lpServiceArgVectors[i]); |
| 690 | lpwstr[i]=usBuffer.Buffer; |
| 691 | } |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 692 | |
Andreas Mohr | 7fb732e | 1999-12-12 00:47:51 +0000 | [diff] [blame] | 693 | StartServiceW(hService, dwNumServiceArgs, (LPCWSTR *)lpwstr); |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 694 | |
| 695 | if(dwNumServiceArgs) |
| 696 | { |
| 697 | for(i=0; i<dwNumServiceArgs; i++) |
| 698 | HeapFree(GetProcessHeap(), 0, lpwstr[i]); |
| 699 | HeapFree(GetProcessHeap(), 0, lpwstr); |
| 700 | } |
| 701 | |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 702 | return TRUE; |
| 703 | } |
| 704 | |
| 705 | |
| 706 | /****************************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 707 | * StartServiceW [ADVAPI32.@] |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 708 | * Starts a service |
| 709 | * |
| 710 | * PARAMS |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 711 | * hService [I] Handle of service |
| 712 | * dwNumServiceArgs [I] Number of arguments |
| 713 | * lpServiceArgVectors [I] Address of array of argument string pointers |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 714 | * |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 715 | * NOTES |
| 716 | * |
| 717 | * NT implements this function using an obscure RPC call... |
| 718 | * |
| 719 | * Might need to do a "setenv SystemRoot \\WINNT" in your .cshrc |
| 720 | * to get things like %SystemRoot%\\System32\\service.exe to load. |
| 721 | * |
| 722 | * Will only work for shared address space. How should the service |
| 723 | * args be transferred when address spaces are separated? |
| 724 | * |
| 725 | * Can only start one service at a time. |
| 726 | * |
Francois Gouget | 3bb9a36 | 2001-10-22 19:04:32 +0000 | [diff] [blame] | 727 | * Has no concept of privilege. |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 728 | * |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 729 | * RETURNS STD |
| 730 | * |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 731 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 732 | BOOL WINAPI |
Patrik Stridvall | 4a73973 | 1999-07-04 11:01:21 +0000 | [diff] [blame] | 733 | StartServiceW( SC_HANDLE hService, DWORD dwNumServiceArgs, |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 734 | LPCWSTR *lpServiceArgVectors ) |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 735 | { |
Matthew Davison | 620323e | 2003-01-24 00:45:51 +0000 | [diff] [blame] | 736 | static const WCHAR _WaitServiceStartW[] = {'A','D','V','A','P','I','_','W', |
| 737 | 'a','i','t','S','e','r','v','i', |
| 738 | 'c','e','S','t','a','r','t',0}; |
| 739 | static const WCHAR _ImagePathW[] = {'I','m','a','g','e','P','a','t','h',0}; |
| 740 | |
| 741 | WCHAR path[MAX_PATH],str[MAX_PATH]; |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 742 | DWORD type,size; |
| 743 | long r; |
| 744 | HANDLE data,wait; |
| 745 | PROCESS_INFORMATION procinfo; |
Matthew Davison | 620323e | 2003-01-24 00:45:51 +0000 | [diff] [blame] | 746 | STARTUPINFOW startupinfo; |
Michael Stefaniuc | cbacde5 | 2002-10-25 19:17:33 +0000 | [diff] [blame] | 747 | TRACE("(%p,%ld,%p)\n",hService,dwNumServiceArgs, |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 748 | lpServiceArgVectors); |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 749 | |
Francois Gouget | 9591836 | 2003-06-18 19:45:22 +0000 | [diff] [blame] | 750 | size = sizeof(str); |
Matthew Davison | 620323e | 2003-01-24 00:45:51 +0000 | [diff] [blame] | 751 | r = RegQueryValueExW(hService, _ImagePathW, NULL, &type, (LPVOID)str, &size); |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 752 | if (r!=ERROR_SUCCESS) |
| 753 | return FALSE; |
Francois Gouget | 9591836 | 2003-06-18 19:45:22 +0000 | [diff] [blame] | 754 | ExpandEnvironmentStringsW(str,path,sizeof(path)); |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 755 | |
Matthew Davison | 620323e | 2003-01-24 00:45:51 +0000 | [diff] [blame] | 756 | TRACE("Starting service %s\n", debugstr_w(path) ); |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 757 | |
Matthew Davison | 620323e | 2003-01-24 00:45:51 +0000 | [diff] [blame] | 758 | data = CreateSemaphoreW(NULL,1,1,_ServiceStartDataW); |
Alexandre Julliard | 7375597 | 2002-07-31 19:26:03 +0000 | [diff] [blame] | 759 | if (!data) |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 760 | { |
Alexandre Julliard | b10dcfe | 2003-10-10 00:05:49 +0000 | [diff] [blame] | 761 | ERR("Couldn't create data semaphore\n"); |
| 762 | return FALSE; |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 763 | } |
Matthew Davison | 620323e | 2003-01-24 00:45:51 +0000 | [diff] [blame] | 764 | wait = CreateSemaphoreW(NULL,0,1,_WaitServiceStartW); |
Alexandre Julliard | b10dcfe | 2003-10-10 00:05:49 +0000 | [diff] [blame] | 765 | if (!wait) |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 766 | { |
Alexandre Julliard | b10dcfe | 2003-10-10 00:05:49 +0000 | [diff] [blame] | 767 | ERR("Couldn't create wait semaphore\n"); |
| 768 | return FALSE; |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 769 | } |
| 770 | |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 771 | /* |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 772 | * FIXME: lpServiceArgsVectors need to be stored and returned to |
| 773 | * the service when it calls StartServiceCtrlDispatcher |
| 774 | * |
| 775 | * Chuck these in a global (yuk) so we can pass them to |
| 776 | * another process - address space separation will break this. |
| 777 | */ |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 778 | |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 779 | r = WaitForSingleObject(data,INFINITE); |
| 780 | |
| 781 | if( r == WAIT_FAILED) |
| 782 | return FALSE; |
| 783 | |
Andreas Mohr | 18a9d74 | 2001-01-17 21:52:42 +0000 | [diff] [blame] | 784 | FIXME("problematic because of address space separation.\n"); |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 785 | start_dwNumServiceArgs = dwNumServiceArgs; |
Andreas Mohr | 7fb732e | 1999-12-12 00:47:51 +0000 | [diff] [blame] | 786 | start_lpServiceArgVectors = (LPWSTR *)lpServiceArgVectors; |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 787 | |
Matthew Davison | 620323e | 2003-01-24 00:45:51 +0000 | [diff] [blame] | 788 | ZeroMemory(&startupinfo,sizeof(STARTUPINFOW)); |
| 789 | startupinfo.cb = sizeof(STARTUPINFOW); |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 790 | |
Matthew Davison | 620323e | 2003-01-24 00:45:51 +0000 | [diff] [blame] | 791 | r = CreateProcessW(path, |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 792 | NULL, |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 793 | NULL, /* process security attribs */ |
| 794 | NULL, /* thread security attribs */ |
| 795 | FALSE, /* inherit handles */ |
| 796 | 0, /* creation flags */ |
| 797 | NULL, /* environment */ |
| 798 | NULL, /* current directory */ |
| 799 | &startupinfo, /* startup info */ |
| 800 | &procinfo); /* process info */ |
| 801 | |
| 802 | if(r == FALSE) |
| 803 | { |
| 804 | ERR("Couldn't start process\n"); |
| 805 | /* ReleaseSemaphore(data, 1, NULL); |
| 806 | return FALSE; */ |
| 807 | } |
| 808 | |
| 809 | /* docs for StartServiceCtrlDispatcher say this should be 30 sec */ |
| 810 | r = WaitForSingleObject(wait,30000); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 811 | |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 812 | ReleaseSemaphore(data, 1, NULL); |
| 813 | |
| 814 | if( r == WAIT_FAILED) |
| 815 | return FALSE; |
| 816 | |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 817 | return TRUE; |
| 818 | } |
| 819 | |
| 820 | /****************************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 821 | * QueryServiceStatus [ADVAPI32.@] |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 822 | * |
| 823 | * PARAMS |
| 824 | * hService [] |
| 825 | * lpservicestatus [] |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 826 | * |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 827 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 828 | BOOL WINAPI |
Patrik Stridvall | 4a73973 | 1999-07-04 11:01:21 +0000 | [diff] [blame] | 829 | QueryServiceStatus( SC_HANDLE hService, LPSERVICE_STATUS lpservicestatus ) |
Matthew Becker | e905f3c | 1999-01-28 13:46:25 +0000 | [diff] [blame] | 830 | { |
Michael McCormack | 75a8413 | 1999-11-21 00:58:14 +0000 | [diff] [blame] | 831 | LONG r; |
| 832 | DWORD type, val, size; |
| 833 | |
Michael Stefaniuc | cbacde5 | 2002-10-25 19:17:33 +0000 | [diff] [blame] | 834 | FIXME("(%p,%p) partial\n",hService,lpservicestatus); |
Michael McCormack | 75a8413 | 1999-11-21 00:58:14 +0000 | [diff] [blame] | 835 | |
| 836 | /* read the service type from the registry */ |
Francois Gouget | 9591836 | 2003-06-18 19:45:22 +0000 | [diff] [blame] | 837 | size = sizeof(val); |
Michael McCormack | 75a8413 | 1999-11-21 00:58:14 +0000 | [diff] [blame] | 838 | r = RegQueryValueExA(hService, "Type", NULL, &type, (LPBYTE)&val, &size); |
| 839 | if(type!=REG_DWORD) |
| 840 | { |
| 841 | ERR("invalid Type\n"); |
| 842 | return FALSE; |
| 843 | } |
| 844 | lpservicestatus->dwServiceType = val; |
Michael McCormack | 75a8413 | 1999-11-21 00:58:14 +0000 | [diff] [blame] | 845 | /* FIXME: how are these determined or read from the registry? */ |
Michael McCormack | 0c0f7d3 | 1999-12-04 04:03:45 +0000 | [diff] [blame] | 846 | /* SERVICE: unavailable=0, stopped=1, starting=2, running=3? */; |
| 847 | lpservicestatus->dwCurrentState = 1; |
Michael McCormack | 75a8413 | 1999-11-21 00:58:14 +0000 | [diff] [blame] | 848 | lpservicestatus->dwControlsAccepted = 0; |
| 849 | lpservicestatus->dwWin32ExitCode = NO_ERROR; |
| 850 | lpservicestatus->dwServiceSpecificExitCode = 0; |
| 851 | lpservicestatus->dwCheckPoint = 0; |
| 852 | lpservicestatus->dwWaitHint = 0; |
| 853 | |
| 854 | return TRUE; |
Juergen Schmied | f7b0de3 | 1999-01-03 12:48:29 +0000 | [diff] [blame] | 855 | } |
Steve Lustbader | f1e1fd0 | 2002-11-25 20:50:53 +0000 | [diff] [blame] | 856 | |
| 857 | /****************************************************************************** |
| 858 | * QueryServiceStatusEx [ADVAPI32.@] |
| 859 | * |
| 860 | * PARAMS |
| 861 | * hService [handle to service] |
| 862 | * InfoLevel [information level] |
| 863 | * lpBuffer [buffer] |
| 864 | * cbBufSize [size of buffer] |
| 865 | * pcbBytesNeeded [bytes needed] |
| 866 | */ |
| 867 | BOOL WINAPI QueryServiceStatusEx(SC_HANDLE hService, SC_STATUS_TYPE InfoLevel, |
| 868 | LPBYTE lpBuffer, DWORD cbBufSize, |
| 869 | LPDWORD pcbBytesNeeded) |
| 870 | { |
| 871 | FIXME("stub\n"); |
| 872 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED); |
| 873 | return FALSE; |
| 874 | } |
Mike McCormack | 9b513ad | 2003-12-02 03:48:53 +0000 | [diff] [blame] | 875 | |
| 876 | /****************************************************************************** |
| 877 | * QueryServiceConfigA [ADVAPI32.@] |
| 878 | */ |
| 879 | BOOL WINAPI |
| 880 | QueryServiceConfigA( SC_HANDLE hService, |
| 881 | LPQUERY_SERVICE_CONFIGA lpServiceConfig, |
| 882 | DWORD cbBufSize, LPDWORD pcbBytesNeeded) |
| 883 | { |
| 884 | FIXME("%p %p %ld %p\n", hService, lpServiceConfig, |
| 885 | cbBufSize, pcbBytesNeeded); |
| 886 | return FALSE; |
| 887 | } |
| 888 | |
| 889 | /****************************************************************************** |
| 890 | * QueryServiceConfigW [ADVAPI32.@] |
| 891 | */ |
| 892 | BOOL WINAPI |
| 893 | QueryServiceConfigW( SC_HANDLE hService, |
| 894 | LPQUERY_SERVICE_CONFIGW lpServiceConfig, |
| 895 | DWORD cbBufSize, LPDWORD pcbBytesNeeded) |
| 896 | { |
| 897 | const WCHAR szDisplayName[] = { |
| 898 | 'D','i','s','p','l','a','y','N','a','m','e', 0 }; |
| 899 | const WCHAR szType[] = {'T','y','p','e',0}; |
| 900 | const WCHAR szStart[] = {'S','t','a','r','t',0}; |
| 901 | const WCHAR szError[] = { |
| 902 | 'E','r','r','o','r','C','o','n','t','r','o','l', 0}; |
| 903 | const WCHAR szImagePath[] = {'I','m','a','g','e','P','a','t','h',0}; |
| 904 | const WCHAR szGroup[] = {'G','r','o','u','p',0}; |
| 905 | const WCHAR szDependencies[] = { |
| 906 | 'D','e','p','e','n','d','e','n','c','i','e','s',0}; |
| 907 | LONG r; |
| 908 | DWORD type, val, sz, total, n; |
| 909 | LPBYTE p; |
| 910 | |
| 911 | TRACE("%p %p %ld %p\n", hService, lpServiceConfig, |
| 912 | cbBufSize, pcbBytesNeeded); |
| 913 | |
| 914 | /* calculate the size required first */ |
| 915 | total = sizeof (QUERY_SERVICE_CONFIGW); |
| 916 | |
| 917 | sz = 0; |
| 918 | r = RegQueryValueExW( hService, szImagePath, 0, &type, NULL, &sz ); |
| 919 | if( ( r == ERROR_SUCCESS ) && ( type == REG_SZ ) ) |
| 920 | total += sz; |
| 921 | |
| 922 | sz = 0; |
| 923 | r = RegQueryValueExW( hService, szGroup, 0, &type, NULL, &sz ); |
| 924 | if( ( r == ERROR_SUCCESS ) && ( type == REG_SZ ) ) |
| 925 | total += sz; |
| 926 | |
| 927 | sz = 0; |
| 928 | r = RegQueryValueExW( hService, szDependencies, 0, &type, NULL, &sz ); |
| 929 | if( ( r == ERROR_SUCCESS ) && ( type == REG_MULTI_SZ ) ) |
| 930 | total += sz; |
| 931 | |
| 932 | sz = 0; |
| 933 | r = RegQueryValueExW( hService, szStart, 0, &type, NULL, &sz ); |
| 934 | if( ( r == ERROR_SUCCESS ) && ( type == REG_SZ ) ) |
| 935 | total += sz; |
| 936 | |
| 937 | sz = 0; |
| 938 | r = RegQueryValueExW( hService, szDisplayName, 0, &type, NULL, &sz ); |
| 939 | if( ( r == ERROR_SUCCESS ) && ( type == REG_SZ ) ) |
| 940 | total += sz; |
| 941 | |
| 942 | /* if there's not enough memory, return an error */ |
| 943 | if( total > *pcbBytesNeeded ) |
| 944 | { |
| 945 | *pcbBytesNeeded = total; |
| 946 | SetLastError( ERROR_INSUFFICIENT_BUFFER ); |
| 947 | return FALSE; |
| 948 | } |
| 949 | |
| 950 | *pcbBytesNeeded = total; |
| 951 | ZeroMemory( lpServiceConfig, total ); |
| 952 | |
| 953 | sz = sizeof val; |
| 954 | r = RegQueryValueExW( hService, szType, 0, &type, (LPBYTE)&val, &sz ); |
| 955 | if( ( r == ERROR_SUCCESS ) || ( type == REG_DWORD ) ) |
| 956 | lpServiceConfig->dwServiceType = val; |
| 957 | |
| 958 | sz = sizeof val; |
| 959 | r = RegQueryValueExW( hService, szStart, 0, &type, (LPBYTE)&val, &sz ); |
| 960 | if( ( r == ERROR_SUCCESS ) || ( type == REG_DWORD ) ) |
| 961 | lpServiceConfig->dwStartType = val; |
| 962 | |
| 963 | sz = sizeof val; |
| 964 | r = RegQueryValueExW( hService, szError, 0, &type, (LPBYTE)&val, &sz ); |
| 965 | if( ( r == ERROR_SUCCESS ) || ( type == REG_DWORD ) ) |
| 966 | lpServiceConfig->dwErrorControl = val; |
| 967 | |
| 968 | /* now do the strings */ |
| 969 | p = (LPBYTE) &lpServiceConfig[1]; |
| 970 | n = total - sizeof (QUERY_SERVICE_CONFIGW); |
| 971 | |
| 972 | sz = n; |
| 973 | r = RegQueryValueExW( hService, szImagePath, 0, &type, p, &sz ); |
| 974 | if( ( r == ERROR_SUCCESS ) || ( type == REG_SZ ) ) |
| 975 | { |
| 976 | lpServiceConfig->lpBinaryPathName = (LPWSTR) p; |
| 977 | p += sz; |
| 978 | n -= sz; |
| 979 | } |
| 980 | |
| 981 | sz = n; |
| 982 | r = RegQueryValueExW( hService, szGroup, 0, &type, p, &sz ); |
| 983 | if( ( r == ERROR_SUCCESS ) || ( type == REG_SZ ) ) |
| 984 | { |
| 985 | lpServiceConfig->lpLoadOrderGroup = (LPWSTR) p; |
| 986 | p += sz; |
| 987 | n -= sz; |
| 988 | } |
| 989 | |
| 990 | sz = n; |
| 991 | r = RegQueryValueExW( hService, szDependencies, 0, &type, p, &sz ); |
| 992 | if( ( r == ERROR_SUCCESS ) || ( type == REG_SZ ) ) |
| 993 | { |
| 994 | lpServiceConfig->lpDependencies = (LPWSTR) p; |
| 995 | p += sz; |
| 996 | n -= sz; |
| 997 | } |
| 998 | |
| 999 | if( n < 0 ) |
| 1000 | ERR("Buffer overflow!\n"); |
| 1001 | |
| 1002 | TRACE("Image path = %s\n", debugstr_w(lpServiceConfig->lpBinaryPathName) ); |
| 1003 | TRACE("Group = %s\n", debugstr_w(lpServiceConfig->lpLoadOrderGroup) ); |
| 1004 | |
| 1005 | return TRUE; |
| 1006 | } |
| 1007 | |
| 1008 | /****************************************************************************** |
| 1009 | * ChangeServiceConfigW [ADVAPI32.@] |
| 1010 | */ |
| 1011 | BOOL WINAPI ChangeServiceConfigW( SC_HANDLE hService, DWORD dwServiceType, |
| 1012 | DWORD dwStartType, DWORD dwErrorControl, LPCWSTR lpBinaryPathName, |
| 1013 | LPCWSTR lpLoadOrderGroup, LPDWORD lpdwTagId, LPCWSTR lpDependencies, |
| 1014 | LPCWSTR lpServiceStartName, LPCWSTR lpPassword, LPCWSTR lpDisplayName) |
| 1015 | { |
| 1016 | FIXME("%p %ld %ld %ld %s %s %p %p %s %s %s\n", |
| 1017 | hService, dwServiceType, dwStartType, dwErrorControl, |
| 1018 | debugstr_w(lpBinaryPathName), debugstr_w(lpLoadOrderGroup), |
| 1019 | lpdwTagId, lpDependencies, debugstr_w(lpServiceStartName), |
| 1020 | debugstr_w(lpPassword), debugstr_w(lpDisplayName) ); |
| 1021 | return TRUE; |
| 1022 | } |
| 1023 | |
| 1024 | /****************************************************************************** |
| 1025 | * ChangeServiceConfigA [ADVAPI32.@] |
| 1026 | */ |
| 1027 | BOOL WINAPI ChangeServiceConfigA( SC_HANDLE hService, DWORD dwServiceType, |
| 1028 | DWORD dwStartType, DWORD dwErrorControl, LPCSTR lpBinaryPathName, |
| 1029 | LPCSTR lpLoadOrderGroup, LPDWORD lpdwTagId, LPCSTR lpDependencies, |
| 1030 | LPCSTR lpServiceStartName, LPCSTR lpPassword, LPCSTR lpDisplayName) |
| 1031 | { |
| 1032 | FIXME("%p %ld %ld %ld %s %s %p %p %s %s %s\n", |
| 1033 | hService, dwServiceType, dwStartType, dwErrorControl, |
| 1034 | debugstr_a(lpBinaryPathName), debugstr_a(lpLoadOrderGroup), |
| 1035 | lpdwTagId, lpDependencies, debugstr_a(lpServiceStartName), |
| 1036 | debugstr_a(lpPassword), debugstr_a(lpDisplayName) ); |
| 1037 | return TRUE; |
| 1038 | } |
Aric Stewart | 3dc71b6 | 2003-12-13 03:25:37 +0000 | [diff] [blame] | 1039 | |
| 1040 | /****************************************************************************** |
| 1041 | * ChangeServiceConfig2A [ADVAPI32.@] |
| 1042 | */ |
| 1043 | BOOL WINAPI ChangeServiceConfig2A( SC_HANDLE hService, DWORD dwInfoLevel, |
| 1044 | LPVOID lpInfo) |
| 1045 | { |
| 1046 | FIXME("STUB: %p %ld %p\n",hService, dwInfoLevel, lpInfo); |
| 1047 | return TRUE; |
| 1048 | } |
| 1049 | |
| 1050 | /****************************************************************************** |
| 1051 | * ChangeServiceConfig2W [ADVAPI32.@] |
| 1052 | */ |
| 1053 | BOOL WINAPI ChangeServiceConfig2W( SC_HANDLE hService, DWORD dwInfoLevel, |
| 1054 | LPVOID lpInfo) |
| 1055 | { |
| 1056 | if (dwInfoLevel == SERVICE_CONFIG_DESCRIPTION) |
| 1057 | { |
| 1058 | static const WCHAR szDescription[] = {'D','e','s','c','r','i','p','t','i','o','n',0}; |
| 1059 | LPSERVICE_DESCRIPTIONW sd = (LPSERVICE_DESCRIPTIONW)lpInfo; |
| 1060 | if (sd->lpDescription) |
| 1061 | { |
| 1062 | TRACE("Setting Description to %s\n",debugstr_w(sd->lpDescription)); |
| 1063 | if (sd->lpDescription[0] == 0) |
| 1064 | RegDeleteValueW(hService,szDescription); |
| 1065 | else |
| 1066 | RegSetValueExW(hService, szDescription, 0, REG_SZ, |
| 1067 | (LPVOID)sd->lpDescription, |
| 1068 | sizeof(WCHAR)*(strlenW(sd->lpDescription)+1)); |
| 1069 | } |
| 1070 | } |
| 1071 | else |
| 1072 | FIXME("STUB: %p %ld %p\n",hService, dwInfoLevel, lpInfo); |
| 1073 | return TRUE; |
| 1074 | } |