Batch file 如何绕过以管理员身份运行命令提示符后出现的弹出窗口?

Batch file 如何绕过以管理员身份运行命令提示符后出现的弹出窗口?,batch-file,cmd,Batch File,Cmd,我正在编写一个批处理文件,该文件包含一些用于安装/卸载windows服务的命令行参数。为了让它执行,它应该具有管理员权限。 我已经添加了代码为它运行作为管理员,我在这里找到 这是我的代码: @echo off REM --> Download link for the redis msi file : https://github.com/microsoftarchive/redis/releases REM --> Redis will be installed as servic

我正在编写一个批处理文件,该文件包含一些用于安装/卸载windows服务的命令行参数。为了让它执行,它应该具有管理员权限。 我已经添加了代码为它运行作为管理员,我在这里找到

这是我的代码:

@echo off
REM --> Download link for the redis msi file : https://github.com/microsoftarchive/redis/releases
REM --> Redis will be installed as service in the system using the installation wizard by clicking the above link.
REM --> Run this batch file after installation of redis in the system.
:-------------------------------------
REM --> Run the command prompt in administrator mode.
:-------------------------------------
echo off

 :: Run this script with elevation
 call :RequestAdminElevation "%~dpfs0" %* || goto:eof

:parse
IF "%~1"=="" echo [91mPlease provide a paramter for running the batch file[0m & GOTO endparse 
IF "%~1"=="--install" echo [92mStarting Redis..[0m & sc start Redis & sc failure Redis reset= 0 actions= restart/0/restart/0/restart/0
IF "%~1"=="--uninstall" echo [91mStopping Redis..[0m & sc stop Redis
:endparse

pause &goto:eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:RequestAdminElevation FilePath %* || goto:eof
:: 
:: Func: opens an admin elevation prompt. If elevated, runs everything after the function call, with elevated rights.
:: Returns: -1 if elevation was requested
::           0 if elevation was successful
::           1 if an error occured
:: 
:: USAGE:
:: If function is copied to a batch file:
::     call :RequestAdminElevation "%~dpf0" %* || goto:eof
::
:: If called as an external library (from a separate batch file):
::     set "_DeleteOnExit=0" on Options
::     (call :RequestAdminElevation "%~dpf0" %* || goto:eof) && CD /D %CD%
::
:: If called from inside another CALL, you must set "_ThisFile=%~dpf0" at the beginning of the file
::     call :RequestAdminElevation "%_ThisFile%" %* || goto:eof
::
:: If you need to use the ! char in the arguments, the calling must be done like this, and afterwards you must use %args% to get the correct arguments:
::      set "args=%* "
::      call :RequestAdminElevation .....   use one of the above but replace the %* with %args:!={a)%
::      set "args=%args:{a)=!%" 
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEDELAYEDEXPANSION & set "_FilePath=%~1"
  if NOT EXIST "!_FilePath!" (echo/Read RequestAdminElevation usage information)
  set "_FN=_%~ns1" & echo/%TEMP%| findstr /C:"(" >nul && (echo/ERROR: %%TEMP%% path can not contain parenthesis &pause &endlocal &fc;: 2>nul & goto:eof)
  :: Remove parenthesis from the temp filename
  set _FN=%_FN:(=%
  set _vbspath="%temp:~%\%_FN:)=%.vbs" & set "_batpath=%temp:~%\%_FN:)=%.bat"

  :: Test if we gave admin rights
  fltmc >nul 2>&1 || goto :_getElevation

  :: Elevation successful
  (if exist %_vbspath% ( del %_vbspath% )) & (if exist %_batpath% ( del %_batpath% )) 
  :: Set ERRORLEVEL 0, set original folder and exit
  endlocal & CD /D "%~dp1" & ver >nul & goto:eof

  :_getElevation
  echo/Requesting elevation...
  :: Try to create %_vbspath% file. If failed, exit with ERRORLEVEL 1
  echo/Set UAC = CreateObject^("Shell.Application"^) > %_vbspath% || (echo/&echo/Unable to create %_vbspath% & endlocal &md; 2>nul &goto:eof) 
  echo/UAC.ShellExecute "%_batpath%", "", "", "runas", 1 >> %_vbspath% & echo/wscript.Quit(1)>> %_vbspath%
  :: Try to create %_batpath% file. If failed, exit with ERRORLEVEL 1
  echo/@%* > "%_batpath%" || (echo/&echo/Unable to create %_batpath% & endlocal &md; 2>nul &goto:eof)
  echo/@if %%errorlevel%%==9009 (echo/^&echo/Admin user could not read the batch file. If running from a mapped drive or UNC path, check if Admin user can read it.)^&echo/^& @if %%errorlevel%% NEQ 0 pause >> "%_batpath%"

  :: Run %_vbspath%, that calls %_batpath%, that calls the original file
  %_vbspath% && (echo/&echo/Failed to run VBscript %_vbspath% &endlocal &md; 2>nul & goto:eof)

  :: Vbscript has been run, exit with ERRORLEVEL -1
  echo/&echo/Elevation was requested on a new CMD window &endlocal &fc;: 2>nul & goto:eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
问题是出现“用户控制访问”弹出窗口,要求获得以管理员身份运行cmd的权限


有没有办法使用我可以添加到文件中的任何命令绕过此弹出窗口?

基本上,答案是否定的,此弹出窗口是Windows内置安全性的一部分。如果人们可以使用自动化流程绕过安全性,它将不再是一个安全的操作系统。根据最佳实践安全建议,可以授予用户完全的管理权限,并将UAC设置为绕过提示。