gpt4 book ai didi

c# - 通过 WMI 自动更新设置

转载 作者:行者123 更新时间:2023-11-30 12:41:24 24 4
gpt4 key购买 nike

尝试从远程服务器的注册表中提取自动更新设置。出于某种原因,即使手动检查 key 为 1-4,它也会返回 0。我忽略了什么?以下片段:

ManagementScope msAutoUpdateReg = new ManagementScope(@"\\" + remoteServer + @"\root\DEFAULT:StdRegProv", connection);
msAutoUpdateReg.Connect();

ManagementClass ci = new ManagementClass(msAutoUpdateReg, new ManagementPath(@"DEFAULT:StdRegProv"), new ObjectGetOptions());
ManagementBaseObject inParams = ci.GetMethodParameters("GetDWORDValue");
inParams["hDefKey"] = 0x80000002; //HKLM
inParams["sSubKeyName"] = @"Software\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update";
inParams["sValueName"] = "AUOptions";
ManagementBaseObject outParams = ci.InvokeMethod("GetDWORDValue", inParams, null);
UInt32 auValue = (UInt32)outParams["uValue"];

if (auValue.ToString() != "0")
{
if (auValue == 1)
{
string currentSetting = "Keep my computer up to date has been disabled in Automatic Updates.";
}

if (auValue == 2)
{
string currentSetting = "Notify of download and installation.";
}

if (auValue == 3)
{
string currentSetting = "Automatically download and notify of installation.";
}

if (auValue == 4)
{
string currentSetting = "Automatically download and scheduled installation.";
}
}
else
{
string currentSetting = "Unknown";
}

最佳答案

我想消除过程可能会有所帮助...

1) 这是只在一台服务器上发生还是在所有服务器上都发生?在你自己的本地机器上怎么样?它是Windows版本的东西吗?例如,我的 Windows 10 盒子似乎没有显示您要查找的子键名称。

2) 如果将 sValueName 更改为“foo”,是否也会得到零? 0 值是否表示错误?

3) 你能否监视 outParams 并检查返回了哪些值?

4) 您是否被 UAC、防火墙或其他权限问题阻止?您可以毫无问题地对该服务器执行其他 WMI 命令吗?您需要以管理员身份运行才能运行吗?

5) 您是否收到其他异常或返回值?我猜您在这里只发布了一部分代码,那么这段代码是在 try/catch block 中吗?

抱歉,如果这听起来含糊或简单,但我认为您可能需要查看哪些有效,哪些无效,以确定您是否可以识别出一种模式。

关于c# - 通过 WMI 自动更新设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37754392/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com