我用如下程序,想启动本机的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");
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");
解决方案 »
- vc中操作XML的最好方法
- VC中如何读取html文件中的某个tag的值(急)
- strPersent.Format( "已下载 %4.2f%s", nPercent*100, "%"); 显示“已下载 -1.#J%”
- 使用Create()手动创建ActiveX 如何指定风格。
- SOKICET 中 重叠IO 模型 为什么要先 WSARecv() ? 内详
- 求字符串加密解密的源程序!
- 菜问题,会者不难谢谢
- 请问如何在一个ATL工程中加入一个ActiveX控件?
- 如何使用CFileDialog时不让更改目录?急,答对者马上给分
- 关于CreatBitmap
- 有关ShellExecute的问题
- 在MDI程序中,如何在程序启动时自动打开或创建某一模板的文档?
BOOL StartService(
SC_HANDLE hService,
DWORD dwNumServiceArgs,
LPCTSTR *lpServiceArgVectors
);
请问,如果我想传个参数列表进去,该怎么办?
例如 a b c d
那么argc=5,argv如何赋值给LPCTSTR *呢?