通过 WMI 设置自定义外壳

本文关键字:外壳 自定义 设置 WMI 通过 | 更新日期: 2023-09-27 18:34:10

我正在尝试在Windows 8.1 IND中设置一个自定义shell,并具有此版本Windows附带的其他锁定功能。

我可以在锁定管理器中成功创建所需的条目,并通过 c# 和 WMI 打开和关闭自定义 shell,没有问题。

因为我们计划部署到大量设备,所以我也想有问题地应用自定义 shell 设置。

我正在使用 WMI 代码生成器来帮助我访问和设置正确的值。

但是,WMI 代码生成器和我的 C# 应用在尝试运行生成器生成的代码来执行此操作时都会崩溃。

Unhandled Exception: System.ArgumentOutOfRangeException: Specified argument was
out of the range of valid values.
Parameter name: path
   at System.Management.ManagementObject.ManagementObjectCTOR(ManagementScope sc
ope, ManagementPath path, ObjectGetOptions options)
   at WMISample.CallWMIMethod.Main()

代码示例:

public static void Main()
        {
            try
            {
                ManagementObject classInstance = 
                    new ManagementObject("root''StandardCimv2''embedded", 
                    "WESL_UserSetting", null);
                // Obtain in-parameters for the method
                ManagementBaseObject inParams = 
                    classInstance.GetMethodParameters("SetCustomShell");
                // Add the input parameters.
                inParams["DefaultAction"] =  3;
                inParams["Shell"] =  "C:''Dash''someapp.exe";
                inParams["Sid"] =  "S-1-5-21-2560287794-1129801719-3036876794-1001";
                // Execute the method and obtain the return values.
                ManagementBaseObject outParams = 
                    classInstance.InvokeMethod("SetCustomShell", inParams, 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);
            }
        }

文档中未提及路径。谁能建议为什么代码没有设置自定义外壳?

通过 WMI 设置自定义外壳

一个老问题,但我通过打开此处指定的外壳启动器解决了这个问题:MSDN。 它位于"打开外壳启动器"部分下。