想是某些细节出了点差错,不过要注意运行的权限一定得是ADMINISTRATORS才行<br>下面两段代码对比一下看看吧,我无论怎么安装/卸载都不出错<br>安装<br> schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE); <br> if (schSCManager == NULL) <br> return FALSE;<br> //...<br> <br> schService = CreateService(schSCManager, internalName, lpszDisplayName,<br> SERVICE_ALL_ACCESS,<br> SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS,<br> SERVICE_AUTO_START,<br> SERVICE_ERROR_IGNORE,<br> lpszBinaryPathName,<br> NULL, NULL, NULL, NULL, NULL);<br> //...<br> CloseServiceHandle(schSCManager); <br> CloseServiceHandle(schService); <br><br><br>卸载<br> hSCM = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);<br><br> if (hSCM != NULL)<br> {<br> hService = OpenService(hSCM, RMSERVICENAME, SERVICE_STOP | DELETE);<br> if (hService != NULL)<br> {<br> ControlService(hService, SERVICE_CONTROL_STOP, &status);<br> bDeleted = DeleteService(hService);<br> CloseServiceHandle(hService);<br> }<br> CloseServiceHandle(hSCM);<br> }