日期:2014-05-16 浏览次数:20712 次
bool CDSvr::DeleteSvr(_TCHAR *svrname){
SC_HANDLE sch=::OpenSCManager(NULL,NULL,SC_MANAGER_CREATE_SERVICE);
if( NULL==sch ){
cout<<"openSCManager failed!"<<endl;
return false;
}
SC_HANDLE sc=::OpenService(sch,svrname,SERVICE_ALL_ACCESS);
if( NULL==sc ){
cout<<"open services failed!"<<endl;
::CloseHandle(sch);
::CloseHandle(sc);
return false;
}
if(::DeleteService(sc)){
cout<<"delete "<<sc<<" SUCCESS"<<endl;
}else{
cout<<"delete "<<sc<<" ERROR"<<endl;
}
::CloseHandle(sch);
::CloseHandle(sc);
return true;
};