2012-07-18 17 views
-2

我想通过使用WMI来获取正在运行的服务的进程。但我很困惑如何使用WMI。如何在C++中设置WMI?

我觉得用这种方法将工作 http://msdn.microsoft.com/en-us/library/system.serviceprocess.servicecontroller.servicename%28v=vs.71%29

但IA不知道如何设置WMI才能使用此

我知道我需要做的这一点,但我不知道哪里去了从那里开始

HRESULT hres(CoInitializeEx(NULL, COINIT_MULTITHREADED)); 
    // Set general COM security levels 
hres = CoInitializeSecurity(
    NULL, 
    -1,        // COM authentication 
    NULL,       // Authentication services 
    NULL,       // Reserved 
    RPC_C_AUTHN_LEVEL_DEFAULT,  // Default authentication 
    RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation 
    NULL,       // Authentication Info 
    EOAC_NONE,      // Additional capabiliteis 
    NULL       // Reserved 
    ); 
+0

我们正在使用的服务应用程序的服务名称 – Bullsfan127 2012-07-18 13:11:15

+2

RTFM:http://msdn.microsoft.com/en-us/library/windows/desktop/aa394558%28v=vs.85%29.aspx – 2012-07-18 13:48:10

回答

0

EnumServicesStatusEx会给你(其中包括)ProcessId的所有活动服务。将其与当前进程的ID进行比较以找到匹配的进程。与ProcessID一起,您将获得每个服务的两个名称:服务名称和显示名称。我不确定哪个你想要的,但大概是其中的一个。