下面是一个VB的例子,怎么用VC实现呀Public Function WmiFillServices() As Service()
Dim Wmi As SWbemObjectSet
Dim WmiObject As SWbemObject
Dim Serv() As Service
Dim Count As Long
 
Set Wmi = GetObject("Winmgmts:{impersonationLevel=impersonate}").InstancesOf("win32_service")
ReDim Serv(Wmi.Count)
 
For Each WmiObject In Wmi
    Serv(Count).ServiceName = WmiObject.Name
    Serv(Count).DisplayName = WmiObject.DisplayName
    Serv(Count).ServiceStart = WmiObject.StartMode
    Serv(Count).ServiceType = WmiObject.ServiceType
    Serv(Count).CurrentState = WmiObject.State
    Serv(Count).Win32ExitCode = WmiObject.exitcode
    Serv(Count).CheckPoint = WmiObject.CheckPoint
    Serv(Count).WaitHint = WmiObject.WaitHint
    Count = Count + 1
Next
End Function

解决方案 »

  1.   

    Winmgmt is a program to invoke WMI (Windows Management Instrumentation), 
    which provides access to information about objects in a managed environment.Check the following KB article:
    Q298130 Err Msg: Winmgmt.exe Has Generated Errors and Will Be Closed...
    http://support.microsoft.com/support/kb/articles/q298/1/30.aspQ263119 Access Violation in WinMgmt Service
    http://support.microsoft.com/support/kb/articles/q263/1/19.asp
      

  2.   

    请先安装WIN2000,然后去下载WMI的SDK(微软的网站有下载)SDK中有实例,很好懂的
      

  3.   

    有个简单的办法
    写一个.vbs的文件,或者去微软网站上下
    在程序中调用
    cscript 文件名.vbs