例如  root\CIMV2   里  Select * From Win32_OperatingSystem   里的方法  ShutDown   
如何引用。

解决方案 »

  1.   

    很遗憾我手里只有c#版的
    strComputer = "." 
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
    Set objShare = objWMIService.Get("Win32_OperatingSystem.ReplaceKeyProperty=ReplacePropertyValue")
    Set objOutParams = objWMIService.ExecMethod("Win32_OperatingSystem.ReplaceKeyProperty=ReplacePropertyValue", "Shutdown")
      

  2.   

    错了
    using System;
    using System.Management;
    using System.Windows.Forms;namespace WMISample
    {
        public class CallWMIMethod
        {
            public static void Main()
            {
                try
                {
                    ManagementObject classInstance = 
                        new ManagementObject("root\\CIMV2", 
                        "Win32_OperatingSystem.ReplaceKeyPropery='ReplaceKeyPropertyValue'",
                        null);                // no method in-parameters to define
                    // Execute the method and obtain the return values.
                    ManagementBaseObject outParams = 
                        classInstance.InvokeMethod("Shutdown", null, null);                // List outParams
                    Console.WriteLine("Out parameters:");
                    Console.WriteLine("ReturnValue: " + outParams["ReturnValue"]);
                }
                catch(ManagementException err)
                {
                    MessageBox.Show("An error occurred while trying to execute the WMI method: " + err.Message);
                }
            }
        }
    }
      

  3.   

     function GetPNPDeviceID():AnsiString;
      var
        Locator: OleVariant;
        WMI: OleVariant;
        RET: OleVariant;
        Enum: IEnumVariant;
        Tmp: OleVariant;
        Value: Cardinal;
      begin
        result:='';
        Locator := CreateOleObject('WbemScripting.SWbemLocator');
        WMI := Locator.ConnectServer('.', '', '', '');
        Ret := WMI.ExecQuery('SELECT * FROM Win32_USBHub');//这里Win32_USBHub为检测项,详见下表
        Enum:= IUnknown(RET._NewEnum) as IEnumVariant;
        while (Enum.Next(1, Tmp, Value) = S_OK) do
        begin
          if Tmp.Name='USB Mass Storage Device' then
          begin
             //ShowMessage('这个u盘的硬件特征码是'+Tmp.PNPDeviceID);//Tmp为检测到返回的数据集合,其中PNPDeviceID为集合中的对象,包含了PID和VID码
             result:=result+Tmp.PNPDeviceID;
          end;
        end;
      end;