delphi 引用 wmi 成员(方法)

karui_mm 2011-12-15 12:40:31
例如 root\CIMV2 里 Select * From Win32_OperatingSystem 里的方法 ShutDown


如何引用。
...全文
201 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
oushengfen 2012-01-18
  • 打赏
  • 举报
回复
 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;
funxu 2011-12-15
  • 打赏
  • 举报
回复
错了
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);
}
}
}
}
funxu 2011-12-15
  • 打赏
  • 举报
回复
很遗憾我手里只有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")

1,184

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧