检测JScript是否处于高架运行状态

Detect if JScript is running elevated?

本文关键字:运行 状态 于高架 JScript 是否 检测      更新时间:2023-09-26

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

OK。我想我明白了。多亏了这张海报,这似乎起作用了:

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