Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 在传递参数时以管理员身份运行.bat文件_Windows_Batch File_Shortcut - Fatal编程技术网

Windows 在传递参数时以管理员身份运行.bat文件

Windows 在传递参数时以管理员身份运行.bat文件,windows,batch-file,shortcut,Windows,Batch File,Shortcut,我有一个.bat文件,它调用第三方应用程序,并添加了一些命令行参数。现在我需要这个应用程序作为管理员运行。我找到了一个创建.bat文件快捷方式的选项,然后将其设置为以管理员身份运行,但我无法以这种方式传递命令行参数 我还找到了另一个选项,可以将其作为.vbs脚本来执行,但我需要从“运行”对话框调用此.vbs文件,运行时需要手动添加.vbs文件的扩展名 在这种情况下,我应该怎么做?请查看以下代码: @ECHO OFF :: this tests if the file is running as

我有一个.bat文件,它调用第三方应用程序,并添加了一些命令行参数。现在我需要这个应用程序作为管理员运行。我找到了一个创建.bat文件快捷方式的选项,然后将其设置为以管理员身份运行,但我无法以这种方式传递命令行参数

我还找到了另一个选项,可以将其作为.vbs脚本来执行,但我需要从“运行”对话框调用此.vbs文件,运行时需要手动添加.vbs文件的扩展名


在这种情况下,我应该怎么做?

请查看以下代码:

@ECHO OFF
:: this tests if the file is running as admin
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if '%errorlevel%' NEQ '0' (GOTO askAdmin)
GOTO gotAdmin
:askAdmin
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
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" )
::from this point you can execute your command as admin
如果你把它放在批处理文件的顶部,它会给用户一个“以管理员身份执行”提示,并以管理员身份重新启动当前批处理文件

——我已经链接了这个特定的答案。