WESL_UserSetting

此类根据登录用户的安全标识符 (SID) 配置 Shell 启动程序将启动的应用程序,并且还配置 Shell 启动程序在应用程序退出时执行的一组返回代码和返回操作。

语法

class WESL_UserSetting {
    [read, write, Required] string Sid;
    [read, write, Required] string Shell;
    [read, write]  Sint32 CustomReturnCodes[];
    [read, write]  Sint32 CustomReturnCodesAction[];
    [read, write] sint32 DefaultAction;

    [Static] uint32 SetCustomShell(
        [In, Required] string Sid,
        [In, Required] string Shell,
        [In] sint32 CustomReturnCodes[],
        [In] sint32 CustomReturnCodesAction[],
        [In] sint32 DefaultAction
    );
    [Static] uint32 GetCustomShell(
        [In, Required] string Sid,
        [Out, Required] string Shell,
        [Out, Required] sint32 CustomReturnCodes[],
        [Out, Required] sint32 CustomReturnCodesAction[],
        [Out, Required] sint32 DefaultAction
    );
    [Static] uint32 RemoveCustomShell(
        [In, Required] string Sid
    );
    [Static] uint32 GetDefaultShell(
        [Out, Required] string Shell,
        [Out, Required] sint32 DefaultAction
    );
    [Static] uint32 SetDefaultShell(
        [In, Required] string Shell,
        [In, Required] sint32 DefaultAction
    );
    [Static] uint32 IsEnabled(
        [Out, Required] boolean Enabled
    );
    [Static] uint32 SetEnabled(
        [In, Required] boolean Enabled);
    );
};

成员

下表列出了属于此类的任何方法和属性。

方法

方法 说明
WESL_UserSetting.SetCustomShell 根据 SID 为特定用户或组配置 Shell 启动程序。
WESL_UserSetting.GetCustomShell 根据 SID 检索特定用户或组的 Shell 启动程序配置。
WESL_UserSetting.RemoveCustomShell 根据 SID 删除特定用户或组的 Shell 启动程序配置。
WESL_UserSetting.GetDefaultShell 检索默认的 Shell 启动程序配置。
WESL_UserSetting.SetDefaultShell 设置默认的 Shell 启动程序配置。
WESL_UserSetting.IsEnabled 检索一个值,该值指示 Shell 启动程序是启用还是禁用。
WESL_UserSetting.SetEnabled 启用或禁用 Shell 启动程序。

属性

属性 数据类型 限定符 说明
Sid 字符串 [read, write, required] 用户或组 SID。
shell 字符串 [read, write, required] 要作为 shell 启动的应用程序。
shell 属性可以是 Path 环境变量中的文件名,也可以包含应用程序的完全限定路径。 还可以在路径中使用环境变量。
shell 属性中的任何空格都必须是用引号分隔的字符串的一部分。
CustomReturnCodes Sint32[] [read, write] 可由 shell 返回的自定义返回码数组。
CustomReturnCodesAction Sint32[] [read, write] 自定义返回代码操作数组,用于确定 Shell 启动程序在 shell 退出时执行的操作。 自定义操作映射到 CustomReturnCodes 数组
可能的操作为:
0 - 重启 shell。
1 - 重启设备。
2 - 关闭设备。
3 - 不执行任何操作。
DefaultAction Sint32 [read, write] Shell 启动程序退出时的默认操作。
可能的操作定义如下:
0 - 重启 shell。
1 - 重启设备。
2 - 关闭设备。
3 - 不执行任何操作。

注解

在具有 Shell 启动程序的设备上只存在一个 WESL_UserSetting 实例。

Shell 启动程序使用为当前登录用户的 SID 定义的自定义配置(如果存在)。 否则,Shell 启动程序将使用为用户所属的组 SID 定义的自定义配置(如果存在)。 如果用户存在多个组自定义配置,Shell 启动程序会使用找到的第一个有效配置。 未定义搜索顺序。

如果用户的 SID 或用户所属的任何组 SID 没有自定义配置,Shell 启动程序将使用默认配置。

可以使用 whoami 命令行工具查找用户和用户所属的任何组的 SID。

示例

以下 Windows PowerShell 脚本演示了如何使用 Shell 启动程序的 Windows Management Instrumentation (WMI) 提供程序为 Shell 启动程序添加和删除自定义 shell 配置。

$COMPUTER = "localhost"
$NAMESPACE = "root\standardcimv2\embedded"

# Create a handle to the class instance so we can call the static methods.
$ShellLauncherClass = [wmiclass]"\\$COMPUTER\${NAMESPACE}:WESL_UserSetting"


# This well-known security identifier (SID) corresponds to the BUILTIN\Administrators group.

$Admins_SID = "S-1-5-32-544"

# Create a function to retrieve the SID for a user account on a machine.

function Get-UsernameSID($AccountName) {

    $NTUserObject = New-Object System.Security.Principal.NTAccount($AccountName)
    $NTUserSID = $NTUserObject.Translate([System.Security.Principal.SecurityIdentifier])

    return $NTUserSID.Value

}

# Get the SID for a user account named "Cashier". Rename "Cashier" to an existing account on your system to test this script.

$Cashier_SID = Get-UsernameSID("Cashier")

# Define actions to take when the shell program exits.

$restart_shell = 0
$restart_device = 1
$shutdown_device = 2
$do_nothing = 3

# Examples

# Set the command prompt as the default shell, and restart the device if it's closed.

$ShellLauncherClass.SetDefaultShell("cmd.exe", $restart_device)

# Display the default shell to verify that it was added correctly.

$DefaultShellObject = $ShellLauncherClass.GetDefaultShell()

"`nDefault Shell is set to " + $DefaultShellObject.Shell + " and the default action is set to " + $DefaultShellObject.defaultaction

# Set Internet Explorer as the shell for "Cashier", and restart the machine if it's closed.

$ShellLauncherClass.SetCustomShell($Cashier_SID, "c:\program files\internet explorer\iexplore.exe www.microsoft.com", ($null), ($null), $restart_shell)

# Set Explorer as the shell for administrators.

$ShellLauncherClass.SetCustomShell($Admins_SID, "explorer.exe")

# View all the custom shells defined.

"`nCurrent settings for custom shells:"
Get-WmiObject -namespace $NAMESPACE -computer $COMPUTER -class WESL_UserSetting | Select Sid, Shell, DefaultAction

# Remove the new custom shells.

$ShellLauncherClass.RemoveCustomShell($Admins_SID)

$ShellLauncherClass.RemoveCustomShell($Cashier_SID)

要求

Windows 版本 支持
Windows 主页
Windows 专业版
Windows 企业版
Windows 教育版
Windows IoT 企业版 是的