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 | 字符串 | [读取、写入、必需] | 用户或组 SID。 |
壳 | 字符串 | [读取、写入、必需] | 要作为 shell 启动的应用程序。 shell 属性可以是 Path 环境变量中的文件名,也可以包含应用程序的完全限定路径。 还可以在路径中使用环境变量。 shell 属性中的任何空格都必须是用引号分隔的字符串的一部分。 |
CustomReturnCodes | Sint32[] | [读取、写入] | 可由 shell 返回的自定义返回代码数组。 |
CustomReturnCodesAction | Sint32[] | [读取、写入] | 自定义返回代码操作的数组,用于确定 Shell 启动程序退出时执行的操作。 自定义操作映射到 CustomReturnCodes 数组。 可能的操作包括: 0 - 重启 shell。 1 - 重启设备。 2 - 关闭设备。 3 - 不执行任何操作。 |
DefaultAction | Sint32 | [读取、写入] | Shell 启动程序退出时执行的默认操作。 可能的操作定义如下: 0 - 重启 shell。 1 - 重启设备。 2 - 关闭设备。 3 - 不执行任何操作。 |
备注
具有 Shell 启动器的设备上仅存在一个 WESL_UserSetting 实例。
Shell 启动器使用为当前登录用户的 SID 定义的自定义配置(如果存在)。 否则,Shell 启动器使用为用户所属的组 SID 定义的自定义配置(如果存在)。 如果用户存在多个组自定义配置,Shell 启动器将使用找到的第一个有效配置。 未定义搜索顺序。
如果用户的 SID 或用户所属的任何组 SID 没有自定义配置,Shell 启动器将使用默认配置。
可以使用 whoami 命令行工具查找用户以及用户所属的任何组的 SID。
示例
以下Windows PowerShell脚本演示如何使用 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 企业版 | 是 |