次の方法で共有


WESL_UserSetting

このクラスは、サインインしているユーザーのセキュリティ識別子 (SID) に基づいて起動するアプリケーションシェル起動ツールを構成し、アプリケーションが終了したときにシェル起動ツールが実行するリターン コードとリターン アクションのセットも構成します。

Windows エディションの要件

次の一覧には、シェル起動ツールをサポートする Windows エディションが含まれています。

✅ Enterprise /Enterprise LTSC
✅ Education
✅ IoT Enterprise / IoT Enterprise LTSC

構文

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);
    );
};

Members

次の表に、このクラスに属するすべてのメソッドとプロパティを示します。

メソッド

メソッド 説明
WESL_UserSetting.SetCustomShell SID に基づいて、特定のユーザーまたはグループのシェル 起動ツールを構成します。
WESL_UserSetting.GetCustomShell SID に基づいて、特定のユーザーまたはグループのシェル 起動ツール構成を取得します。
WESL_UserSetting.RemoveCustomShell SID に基づいて、特定のユーザーまたはグループのシェル 起動ツール構成を削除します。
WESL_UserSetting.GetDefaultShell 既定のシェル 起動ツール構成を取得します。
WESL_UserSetting.SetDefaultShell シェル起動ツールの既定の構成を設定します。
WESL_UserSetting.IsEnabled シェル 起動ツールが有効か無効か示す値を取得します。
WESL_UserSetting.SetEnabled シェル起動ツールを有効または無効にします。

プロパティ

プロパティ データ型 修飾子 説明
Sid 文字列 [読み取り、書き込み、必須] ユーザーまたはグループ SID。
文字列 [読み取り、書き込み、必須] シェルとして起動するアプリケーション。
シェル プロパティは、Path 環境変数内のファイル名にすることも、アプリケーションへの完全修飾パスを含めることもできます。 パスで環境変数を使用することもできます。
シェル プロパティ内のスペースは、引用符で区切られた文字列の一部である必要があります。
CustomReturnCodes Sint32[] [読み取り、書き込み] シェルから返すことができるカスタム戻りコードの配列。
CustomReturnCodesAction Sint32[] [読み取り、書き込み] シェルの終了時にシェル起動ツールが実行するアクションを決定するカスタムリターンコードアクションの配列。 カスタム アクションは CustomReturnCodes の配列にマップされます。
考えられるアクションは次のとおりです。
0 - シェルを再起動します。
1 - デバイスを再起動します。
2 - デバイスをシャットダウンします。
3 - 何もしません。
DefaultAction Sint32 [読み取り、書き込み] シェル起動ツールは、シェルが終了したときに実行される既定のアクションです。
考えられるアクションは次のように定義されます。
0 - シェルを再起動します。
1 - デバイスを再起動します。
2 - デバイスをシャットダウンします。
3 - 何もしません。

注釈

シェル起動ツール を使用する デバイスには、WESL_UserSetting インスタンスが 1 つだけ存在します。

シェル起動ツールは、現在サインインしているユーザーの SID に対して定義されているカスタム構成 (存在する場合) を使用します。 それ以外の場合、シェル起動ツールは、ユーザーがメンバーであるグループ SID に対して定義されたカスタム構成 (存在する場合) を使用します。 ユーザーに対して複数のグループ カスタム構成が存在する場合、シェル起動ツールは最初に検出した有効な構成を使用します。 検索順序が定義されていません。

ユーザーの SID またはユーザーがメンバーであるグループ SID のカスタム構成がない場合、シェル起動ツールは既定の構成を使用します。

whoami コマンド ライン ツールを使用して、ユーザーとユーザーがメンバーになっているすべてのグループの SID を見つけることができます。

次のWindows PowerShell スクリプトは、シェル起動ツール用の Windows Management Instrumentation (WMI) プロバイダーを使用して、シェル起動ツールのカスタム シェル構成を追加および削除する方法を示しています。

$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)