WESL_UserSetting
此類別會根據已登入使用者的安全標識碼 (SID) 來設定啟動哪一個應用程式殼層啟動器,也會設定Shell Launcher 在應用程式結束時執行的一組傳回碼和傳回動作。
語法
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 Launcher。 |
WESL_UserSetting.GetCustomShell | 根據 SID 擷取特定使用者或群組的 Shell Launcher 設定。 |
WESL_UserSetting.RemoveCustomShell | 根據 SID,移除特定使用者或群組的 Shell Launcher 設定。 |
WESL_UserSetting.GetDefaultShell | 擷取預設殼層啟動器組態。 |
WESL_UserSetting.SetDefaultShell | 設定預設殼層啟動器組態。 |
WESL_UserSetting.IsEnabled | 擷取值,指出殼層啟動器是啟用或停用。 |
WESL_UserSetting.SetEnabled | 啟用或停用Shell Launcher。 |
屬性
屬性 | 資料類型 | 限定 符 | 描述 |
---|---|---|---|
Sid | string | [讀取、寫入、必要] | 使用者或群組 SID。 |
殼 | string | [讀取、寫入、必要] | 要作為殼層啟動的應用程式。 Shell 屬性可以是Path環境變數中的檔名,也可以包含應用程式的完整路徑。 您也可以在路徑中使用環境變數。 Shell 屬性中的任何空格都必須是引號分隔字串的一部分。 |
CustomReturnCodes | Sint32[] | [讀取、寫入] | 殼層可傳回的自定義傳回碼數位數組。 |
CustomReturnCodesAction | Sint32[] | [讀取、寫入] | 自定義傳回碼動作的陣列,決定Shell Launcher 在殼層結束時所採取的動作。 自定義動作會對應至 CustomReturnCodes 的陣列。 可能的動作為: 0 - 重新啟動殼層。 1 - 重新啟動裝置。 2 - 關閉裝置。 3 - 不執行任何動作。 |
DefaultAction | Sint32 | [讀取、寫入] | Shell Launcher 在殼層結束時所採取的默認動作。 可能的動作定義如下: 0 - 重新啟動殼層。 1 - 重新啟動裝置。 2 - 關閉裝置。 3 - 不執行任何動作。 |
備註
具有Shell Launcher的裝置上只有一個 WESL_UserSetting 實例。
殼層啟動器會使用針對目前登入之使用者的 SID 所定義的自定義組態,如果有的話。 否則,如果有任何存在,Shell Launcher 會針對使用者所屬的群組 SID 使用定義的自定義組態。 如果使用者有多個群組自定義組態存在,Shell Launcher 會使用它找到的第一個有效組態。 未定義搜尋順序。
如果使用者的 SID 或使用者所屬的任何群組 SID 沒有自定義組態,Shell Launcher 會使用預設組態。
您可以使用 whoami 命令列工具,找到使用者的 SID 以及使用者所屬的任何群組。
範例
下列 Windows PowerShell 腳本示範如何使用 Shell Launcher 的 Windows Management Instrumentation (WMI) 提供者,來新增和移除 Shell Launcher 的自定義殼層設定。
$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 企業版 | 是 |