- Timestamp:
- Dec 18, 2017 8:41:37 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxGuest/win/VBoxGuestInst.cpp
r70194 r70209 101 101 return -1; 102 102 } 103 SC_HANDLE hService = OpenService(hSMgr, VBOXGUEST_SERVICE_NAME, DELETE);103 SC_HANDLE hService = OpenService(hSMgr, VBOXGUEST_SERVICE_NAME, SERVICE_STOP | SERVICE_QUERY_STATUS | DELETE); 104 104 if (hService) 105 105 { 106 /* 107 * Try stop it if it's running. 108 */ 109 SERVICE_STATUS Status = { 0, 0, 0, 0, 0, 0, 0 }; 110 QueryServiceStatus(hService, &Status); 111 if (Status.dwCurrentState == SERVICE_STOPPED) 112 rc = VINF_SUCCESS; 113 else if (ControlService(hService, SERVICE_CONTROL_STOP, &Status)) 114 { 115 int iWait = 100; 116 while (Status.dwCurrentState == SERVICE_STOP_PENDING && iWait-- > 0) 117 { 118 Sleep(100); 119 QueryServiceStatus(hService, &Status); 120 } 121 if (Status.dwCurrentState == SERVICE_STOPPED) 122 rc = VINF_SUCCESS; 123 else 124 { 125 printf("Failed to stop service. status=%d (%#x)\n", Status.dwCurrentState, Status.dwCurrentState); 126 rc = VERR_GENERAL_FAILURE; 127 } 128 } 129 else 130 { 131 DWORD dwErr = GetLastError(); 132 if ( Status.dwCurrentState == SERVICE_STOP_PENDING 133 && dwErr == ERROR_SERVICE_CANNOT_ACCEPT_CTRL) 134 rc = VERR_RESOURCE_BUSY; /* better than VERR_GENERAL_FAILURE */ 135 else 136 { 137 printf("ControlService failed with dwErr=%u. status=%d (%#x)\n", 138 dwErr, Status.dwCurrentState, Status.dwCurrentState); 139 rc = -1; 140 } 141 } 142 106 143 /* 107 144 * Delete the service. 108 145 */ 109 if (DeleteService(hService)) 110 rc = 0; 111 else 112 printf("DeleteService failed lasterr=%d\n", GetLastError()); 146 if (RT_SUCCESS(rc)) 147 { 148 if (DeleteService(hService)) 149 rc = 0; 150 else 151 { 152 printf("DeleteService failed lasterr=%d\n", GetLastError()); 153 rc = -1; 154 } 155 } 113 156 CloseServiceHandle(hService); 114 157 }
Note:
See TracChangeset
for help on using the changeset viewer.