1. bool StopNoNeedServices(LPCWSTR ServerName) 
  2.     SC_HANDLE hScm, hService; 
  3.     SERVICE_STATUS status; 
  4.  
  5.     hScm = OpenSCManager(NULL,NULL,SC_MANAGER_CREATE_SERVICE); 
  6.     hService = OpenService(hScm,ServerName,SERVICE_ALL_ACCESS|DELETE); 
  7.     BOOL isSuccess = QueryServiceStatus(hService,&status); 
  8.     //指定服务不存在 
  9.     if (!isSuccess) 
  10.     { 
  11.         return true
  12.     } 
  13.  
  14.     if ( status.dwCurrentState != SERVICE_STOPPED ) 
  15.     { 
  16.         //停用服务 
  17.         DWORD dRt = ControlService(hService,SERVICE_CONTROL_STOP,&status); 
  18.         if (!dRt) 
  19.         { 
  20.             cout<<"failed to stop the services "<<UnicodeToAscii(ServerName).c_str()<<endl; 
  21.             DWORD dError = GetLastError(); 
  22.  
  23.             return false
  24.         } 
  25.         else 
  26.             cout<<"success to stop the services "<<UnicodeToAscii(ServerName).c_str()<<endl; 
  27.     } 
  28.  
  29.     //禁用服务 
  30.     if ( !ChangeServiceConfig(hService,SERVICE_NO_CHANGE,SERVICE_DISABLED,SERVICE_NO_CHANGE,NULL,NULL,NULL,NULL,NULL,NULL,NULL) )             
  31.     { 
  32.         cout<<"failed to disabled the services."<<endl; 
  33.     } 
  34.  
  35.     ::CloseServiceHandle( hService); 
  36.     ::CloseServiceHandle( hScm); 
  37.  
  38.     return true