Changeset 25795 in vbox for trunk/src/VBox/Additions/common
- Timestamp:
- Jan 13, 2010 8:43:46 AM (15 years ago)
- Location:
- trunk/src/VBox/Additions/common/VBoxService
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxService-win.cpp
r25166 r25795 26 26 #include <iprt/assert.h> 27 27 #include <iprt/err.h> 28 #include <iprt/ldr.h> 28 29 #include <VBox/VBoxGuestLib.h> 29 30 #include "VBoxServiceInternal.h" … … 35 36 DWORD g_rcWinService = 0; 36 37 SERVICE_STATUS_HANDLE g_hWinServiceStatus = NULL; 38 39 /** Dynamically loaded function ChangeServiceConfig2() which is not available in NT4. */ 40 typedef BOOL (WINAPI FNCHANGESERVICECONFIG2) (SC_HANDLE hService, DWORD dwInfoLevel, LPVOID lpInfo); 41 /** Pointer to FNCHANGESERVICECONFIG2. */ 42 typedef FNCHANGESERVICECONFIG2 *PFNCHANGESERVICECONFIG2; 37 43 38 44 void WINAPI VBoxServiceWinMain (DWORD argc, LPTSTR *argv); … … 146 152 VBoxServiceVerbose(1, "Installing service ...\n"); 147 153 148 hSCManager = OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS); 149 150 if (NULL == hSCManager) { 151 VBoxServiceError("Could not open SCM! Error: %d\n", GetLastError()); 154 hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); 155 156 if (NULL == hSCManager) 157 { 158 VBoxServiceError("Could not open SCM! Error: %ld\n", GetLastError()); 152 159 return 1; 153 160 } … … 157 164 SERVICE_ALL_ACCESS, 158 165 SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS, 159 SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL,166 SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, 160 167 imagePath, NULL, NULL, NULL, NULL, NULL); 161 162 if (NULL == hService) { 163 VBoxServiceError("Could not create service! Error: %d\n", GetLastError()); 164 CloseServiceHandle(hSCManager); 165 return 1; 168 int rc = VINF_SUCCESS; 169 if (NULL == hService) 170 { 171 DWORD dwErr = GetLastError(); 172 switch (dwErr) 173 { 174 175 case ERROR_SERVICE_EXISTS: 176 177 VBoxServiceVerbose(1, "Service already exists, just updating the service config.\n"); 178 hService = OpenService (hSCManager, 179 VBOXSERVICE_NAME, 180 SERVICE_ALL_ACCESS); 181 if (NULL == hService) 182 { 183 VBoxServiceError("Could not open service! Error: %ld\n", GetLastError()); 184 rc = 1; 185 } 186 else 187 { 188 if (ChangeServiceConfig (hService, 189 SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS, 190 SERVICE_DEMAND_START, 191 SERVICE_ERROR_NORMAL, 192 imagePath, 193 NULL, 194 NULL, 195 NULL, 196 NULL, 197 NULL, 198 VBOXSERVICE_FRIENDLY_NAME)) 199 { 200 /* On W2K+ there's ChangeServiceConfig2() which lets us set some fields 201 like a longer service description. */ 202 #ifndef TARGET_NT4 203 SERVICE_DESCRIPTION desc; 204 /** @todo On Vista+ SERVICE_DESCRIPTION also supports localized strings! */ 205 desc. lpDescription = VBOXSERVICE_DESCRIPTION; 206 if (FALSE == ChangeServiceConfig2(hService, 207 SERVICE_CONFIG_DESCRIPTION, /* Service info level */ 208 &desc)) 209 { 210 VBoxServiceError("Cannot set the service description! Error: %ld\n", GetLastError()); 211 } 212 #endif 213 214 VBoxServiceVerbose(1, "The service config has been successfully updated.\n"); 215 } 216 else 217 { 218 VBoxServiceError("Could not change service config! Error: %ld\n", GetLastError()); 219 rc = 1; 220 } 221 } 222 break; 223 224 default: 225 226 VBoxServiceError("Could not create service! Error: %ld\n", dwErr); 227 rc = 1; 228 break; 229 } 166 230 } 167 231 else … … 172 236 CloseServiceHandle(hService); 173 237 CloseServiceHandle(hSCManager); 174 175 return 0; 238 return rc; 176 239 } 177 240 -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceInternal.h
r25166 r25795 97 97 #define VBOXSERVICE_NAME "VBoxService" 98 98 /** The friendly service name. */ 99 #define VBOXSERVICE_FRIENDLY_NAME "VBoxService" 99 #define VBOXSERVICE_FRIENDLY_NAME "VirtualBox Guest Additions Service" 100 /** The service description (only W2K+ atm) */ 101 #define VBOXSERVICE_DESCRIPTION "Manages VM runtime information, time synchronization, remote sysprep execution and miscellaneous utilities for guest operating systems." 100 102 /** The following constant may be defined by including NtStatus.h. */ 101 103 #define STATUS_SUCCESS ((NTSTATUS)0x00000000L)
Note:
See TracChangeset
for help on using the changeset viewer.