Changeset 36941 in vbox for trunk/src/VBox/HostDrivers/win/cfg/VBoxDrvCfg.cpp
- Timestamp:
- May 3, 2011 2:56:08 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/win/cfg/VBoxDrvCfg.cpp
r36871 r36941 637 637 { 638 638 winEr = GetLastError(); 639 Assert(winEr == ERROR_CLASS_MISMATCH);639 // Assert(winEr == ERROR_CLASS_MISMATCH); 640 640 if (winEr != ERROR_CLASS_MISMATCH) 641 641 { … … 714 714 } 715 715 716 /* time intervals in milliseconds */ 717 /* max time to wait for the service to startup */ 718 #define VBOXDRVCFG_SVC_WAITSTART_TIME 10000 719 /* sleep time before service status polls */ 720 #define VBOXDRVCFG_SVC_WAITSTART_TIME_PERIOD 100 721 /* number of service start polls */ 722 #define VBOXDRVCFG_SVC_WAITSTART_RETRIES (VBOXDRVCFG_SVC_WAITSTART_TIME/VBOXDRVCFG_SVC_WAITSTART_TIME_PERIOD) 723 724 VBOXDRVCFG_DECL(HRESULT) VBoxDrvCfgSvcStart(LPCWSTR lpszSvcName) 725 { 726 SC_HANDLE hMgr = OpenSCManager(NULL, NULL, SERVICE_QUERY_STATUS | SERVICE_START); 727 if (hMgr == NULL) 728 { 729 DWORD winEr = GetLastError(); 730 LogRel((__FUNCTION__": OpenSCManager failed, winEr (%d)\n", winEr)); 731 return HRESULT_FROM_WIN32(winEr); 732 } 733 734 HRESULT hr = S_OK; 735 SC_HANDLE hSvc = OpenServiceW(hMgr, lpszSvcName, SERVICE_QUERY_STATUS | SERVICE_START); 736 if (hSvc) 737 { 738 do 739 { 740 SERVICE_STATUS Status; 741 BOOL fRc = QueryServiceStatus(hSvc, &Status); 742 if (!fRc) 743 { 744 DWORD winEr = GetLastError(); 745 LogRel((__FUNCTION__": QueryServiceStatus failed winEr (%d)\n", winEr)); 746 hr = HRESULT_FROM_WIN32(winEr); 747 break; 748 } 749 750 if (Status.dwCurrentState != SERVICE_RUNNING && Status.dwCurrentState != SERVICE_START_PENDING) 751 { 752 LogRel(("Starting service (%S)\n", lpszSvcName)); 753 754 fRc = StartService(hSvc, 0, NULL); 755 if (!fRc) 756 { 757 DWORD winEr = GetLastError(); 758 LogRel((__FUNCTION__": StartService failed winEr (%d)\n", winEr)); 759 hr = HRESULT_FROM_WIN32(winEr); 760 break; 761 } 762 } 763 764 fRc = QueryServiceStatus(hSvc, &Status); 765 if (!fRc) 766 { 767 DWORD winEr = GetLastError(); 768 LogRel((__FUNCTION__": QueryServiceStatus failed winEr (%d)\n", winEr)); 769 hr = HRESULT_FROM_WIN32(winEr); 770 break; 771 } 772 773 if (Status.dwCurrentState == SERVICE_START_PENDING) 774 { 775 for (int i = 0; i < VBOXDRVCFG_SVC_WAITSTART_RETRIES; ++i) 776 { 777 Sleep(VBOXDRVCFG_SVC_WAITSTART_TIME_PERIOD); 778 fRc = QueryServiceStatus(hSvc, &Status); 779 if (!fRc) 780 { 781 DWORD winEr = GetLastError(); 782 LogRel((__FUNCTION__": QueryServiceStatus failed winEr (%d)\n", winEr)); 783 hr = HRESULT_FROM_WIN32(winEr); 784 break; 785 } 786 else if (Status.dwCurrentState != SERVICE_START_PENDING) 787 break; 788 } 789 } 790 791 if (hr != S_OK || Status.dwCurrentState != SERVICE_RUNNING) 792 { 793 LogRel((__FUNCTION__": Failed to start the service\n")); 794 hr = E_FAIL; 795 break; 796 } 797 798 } while (0); 799 800 CloseServiceHandle(hSvc); 801 } 802 else 803 { 804 DWORD winEr = GetLastError(); 805 LogRel((__FUNCTION__": OpenServiceW failed, winEr (%d)\n", winEr)); 806 hr = HRESULT_FROM_WIN32(winEr); 807 } 808 809 CloseServiceHandle(hMgr); 810 811 return hr; 812 }
Note:
See TracChangeset
for help on using the changeset viewer.