检测脚本是否正在升级?

时间:2013-06-15 04:31:13

标签: javascript windows jscript wsh windows-scripting

我有一个JScript,它设计用于在.js文件(而不是Web浏览器脚本)的Windows平台上运行。我可以检测我的脚本是在运行提升还是具有管理权限?

1 个答案:

答案 0 :(得分:0)

行。我想我明白了。感谢this poster,这似乎有效:

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