我在注册表中找到了位置。
但是除了注册表外,应该有什么函数调用可以获得一个服务的具体资料吧?
请指教!

解决方案 »

  1.   

    IADsService接口的get_Path方法可以获得该信息
      

  2.   

    //首先你要取得当前所运行的程序,取得该句柄
    HANDLE m_handle=::CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);
    PROCESSENTRY32* Info = new PROCESSENTRY32;
    CString ss;
    Info->dwSize = sizeof(PROCESSENTRY32);
    if(::Process32First(m_handle,Info))
    {
    while(::Process32Next(m_handle,Info)!=FALSE)
    {
    ss=Info->szExeFile;
    ss.MakeLower();
    if(ss.Find("程序名") != -1)
    {
    return Info->th32ProcessID;
    }
    }
    ::CloseHandle(m_handle);
    if(Info)
    {
    delete Info;
    }
    }
    ......
    DWORD filename;
    filename=GetModuleFileName(Info->th32ModuleID,......);
    ......程序简单修改,就可以得到所有的当前运行的程序(当然包括服务)的文件
      

  3.   

    可以用以下函数获得
    QueryServiceConfig
    当然,你先得打开服务管理器,再打开服务。如果你搞服务端软件开发,这点应该没问题的。呵呵
    然后可以queryserviceConfig获得详细信息,其中有你要的lpBinaryPathName。QueryServiceConfig
    The QueryServiceConfig function retrieves the configuration parameters of the specified service. BOOL QueryServiceConfig(
      SC_HANDLE hService,  // handle of service
      LPQUERY_SERVICE_CONFIG lpServiceConfig,
                           // address of service config. structure
      DWORD cbBufSize,     // size of service configuration buffer
      LPDWORD pcbBytesNeeded   // address of variable for bytes needed
    );
    typedef struct _QUERY_SERVICE_CONFIG { // qsc 
        DWORD dwServiceType; 
        DWORD dwStartType; 
        DWORD dwErrorControl; 
        LPTSTR lpBinaryPathName;  // 这就是你要的值,
        LPTSTR lpLoadOrderGroup; 
        DWORD dwTagId; 
        LPTSTR lpDependencies; 
        LPTSTR lpServiceStartName; 
        LPTSTR lpDisplayName; 
    } QUERY_SERVICE_CONFIG, LPQUERY_SERVICE_CONFIG; 
      

  4.   

    NT下也可以使用活动目录的
    IADsService
    ...
    Requirements 
      Windows NT/2000 or later: Requires Windows 2000 or later (or Windows NT 4.0 SP6a or later with Active Directory Client Extension).
      

  5.   

    依据进程句柄获取可执行文件全名(包括路径):
    getmodulefilename()
    根据文件名获取进程名
    getmodulehandle()
    详细请查msdn这两个函数都有参数