如何 运行 命令提示符 运行 作为管理员使用批处理文件

How to run a Command Prompt run as a Administrator using batch file

我想要 运行 一个 jar 文件,jar 文件内容一些外部命令所以需要它作为 运行 管理员,所以我希望它 运行 不使用批处理文件 运行 作为管理员

您可以 运行 使用右键单击它并 select 运行 作为管理员或以下代码内容批处理文件代码 运行 作为管理员。

@echo off
:: BatchGotAdmin (Run as Admin code starts)
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"
:: BatchGotAdmin (Run as Admin code ends)
:: Your codes should start from the following line
C:
test.jar