【问题标题】:WMI RegDword getvalue and setvalueWMI RegDword 获取值和设置值
【发布时间】:2011-12-16 12:37:44
【问题描述】:

我无法从 USBSTOR 注册表项中获取 REG_DWORD 数据,但我可以获取 REG_SZ 类型的“DisplayName”数据

ManagementScope myScope = new ManagementScope("\\\\" + strComputer + "\\root\\default");
ManagementPath mypath = new ManagementPath("StdRegProv");
ManagementClass mc = new ManagementClass(myScope, mypath, null);
ManagementBaseObject inParams = mc.GetMethodParameters("GetStringValue");
inParams["sSubKeyName"] = @"SYSTEM\CurrentControlSet\services\USBSTOR";
inParams["sValueName"] = "DisplayName";
ManagementBaseObject outParams = mc.InvokeMethod("GetStringValue", inParams, null);
Console.WriteLine(outParams["Type"].ToString());

【问题讨论】:

    标签: c# registry wmi


    【解决方案1】:

    如果数据类型是 REG_DWORD,你应该使用 GetDWORDValue 方法,如果数据类型是 REG_SZ,你应该使用 GetStringValue 方法:

    ManagementBaseObject inParams = mc.GetMethodParameters("GetDWORDValue");
    inParams["sSubKeyName"] = @"SYSTEM\CurrentControlSet\services\USBSTOR";
    inParams["sValueName"] = "Type";
    ManagementBaseObject outParams = mc.InvokeMethod("GetDWORDValue", inParams, null);
    UInt32 uValue = (UInt32)outParams["uValue"];
    //...
    ManagementBaseObject inParams = mc.GetMethodParameters("GetStringValue");
    inParams["sSubKeyName"] = @"SYSTEM\CurrentControlSet\services\USBSTOR";
    inParams["sValueName"] = "DisplayName";
    ManagementBaseObject outParams = mc.InvokeMethod("GetStringValue", inParams, null);
    string sValue = (string)outParams["sValue"];
    

    【讨论】:

    • DimitryG 如果我已经安装了 USB 的驱动程序并且我将起始值设置为 4,那么 USB 将运行但如果这是第一次它不会是真的吗?如果我想阻止它,即使驱动程序已安装,你知道任何方法吗?
    • 很遗憾,我无法就这个问题给你确切的答案。请检查this article
    • 从这篇文章我可以发现为什么你不能给我确切的答案,但感谢你的帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-12
    相关资源
    最近更新 更多