2

Windows プラットフォームで実行するように設計された .js ファイル (Web ブラウザー スクリプトではない) の JScript があります。スクリプトが管理者特権で実行されているかどうかを検出できますか?

4

1 に答える 1

0

わかった。私はそれを手に入れたと思います。このポスターのおかげで、これはうまくいくようです:

function isRunningElevated()
{
    //Checks if this scrpt is running elevated
    //RETURN:
    //      = 'true' if yes
    var res = runCommandNoWindow("net session");
    return res === 0;
}

function runCommandNoWindow(strCmd)
{
    //Run command
    //RETURN:
    //      = Integer returned by the command
    var res = null;

    try
    {
        var oShell = WScript.CreateObject("WScript.Shell");
        res = oShell.Run(strCmd, 0, true);  //No window, wait to finish!
    }
    catch(e)
    {
        //Failed
        res = null;
    }

    return res;
}
于 2013-06-15T05:37:31.880 に答える