我想通过编程改变服务的启动方式代码如下,但不成功,我觉得方法应该没问题的,应该是某些参数用得不对。
char *strname=new char[100];
SC_HANDLE SCH_Manger=::OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS);
if (SCH_Manger==NULL)
{
DWORD dwCode=GetLastError();
CString strCode;
strCode.Format("%d",dwCode);
MessageBox(strCode);  //运行到此StrCode=1598884628为什么
return;
}
SC_HANDLE SCH_Service=::OpenService(SCH_Manger,"Network Connections",SERVICE_ALL_ACCESS);
if (SCH_Service==NULL)
{
DWORD dwCode=GetLastError();
CString strCode;
strCode.Format("%d",strCode);
MessageBox(strCode);  //运行到此strCode=1598884628为什么
return;
}
BOOL retval=ChangeServiceConfig(SCH_Service,
                            SERVICE_WIN32_OWN_PROCESS,
                            SERVICE_DISABLED,
            SERVICE_ERROR_NORMAL,
            NULL,NULL,NULL,NULL,NULL,NULL,strname);
if(retval==0)
{   
DWORD dwCode;
CString strError;
dwCode=GetLastError();
strError.Format("Confic Services Fail!(%d)",dwCode);
MessageBox(strError);
}

解决方案 »

  1.   

    运行到此strCode=1598884628为什么
    =================
    出错了,
    看错误宏定义, 这个值是什么意思, 记不住...
      

  2.   

    我用ErrorLookUp 查找这个错误代码(1598884628),提示“Message Not Found !”
      

  3.   

    Many operations require an open handle to an SCManager object. The following example demonstrates how to obtain the handle. Different operations on the SCM database require different levels of access, and you should only request the minimum access required. If SC_MANAGER_ALL_ACCESS is requested, the OpenSCManager function fails if the calling process does not have administrator privileges. The following example shows how to request full access to the ServicesActive database on the local machine.