我用如下程序,想启动本机的telnet服务“TlntSvr”:
char ServiceName[] ="TlntSvr";
SC_HANDLE hSCM=NULL,hSCS=NULL; 
SERVICE_STATUS ServiceStatus; 
CString tempstr;
hSCM=OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS); hSCS=OpenService(hSCM,ServiceName,SERVICE_ALL_ACCESS);

DWORD argc = 1;
LPCTSTR * argv = NULL;
if(StartService(hSCS,argc,argv)) { 
AfxMessageBox("Service is starting.....");
}
else{
Sleep(30);
while(QueryServiceStatus(hSCS,&ServiceStatus)) { 
tempstr.Format("%d",ServiceStatus.dwCurrentState);
AfxMessageBox(tempstr);
if(ServiceStatus.dwCurrentState==SERVICE_START_PENDING) 
Sleep(30); 
else break; 
         }


if(ServiceStatus.dwCurrentState==SERVICE_RUNNING) 
AfxMessageBox("Service is already started!");
else
AfxMessageBox("Service is not started");