21
2021
05
10:22:49

bat运行自动提权



推荐点击下面图片,通过本站淘宝优惠价购买:

image.png

@echo off

:: BatchGotAdmin
:-------------------------------------REM  --> Check for permissions>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"REM --> If error flag set, we do not have admin.if '%errorlevel%' NEQ '0' (    echo Requesting administrative privileges...
    goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"

    "%temp%\getadmin.vbs"
    exit /B

:gotAdmin    if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
    pushd "%CD%"
    CD /D "%~dp0":--------------------------------------

<YOUR BATCH SCRIPT HERE>


Basically this just creates a VBS Script on the fly and invokes the batch script using it.  It checks to see if the current window is running as administrator by attempting to create a folder that requires administrative access.  If the directory can not be created, then it invokes the UAC dialog, then closes the non-admin window.  The script can also be executed from an already open administrative CLI.

https://sites.google.com/site/eneerge/home/BatchGotAdmin


本文链接:https://hqyman.cn/post/1732.html 非本站原创文章欢迎转载,原创文章需保留本站地址!

分享到:





休息一下,本站随机推荐观看栏目:


« 上一篇 下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

您的IP地址是: