详细的回答 : 有很多烦躁的细节; 参见我的博客条目 < a href = “ http://montgomeryMinds.com/blog/Start-program-WITHOUT-UAC-used-at-system-Start/”rel = “ noreference rer”> “ Start program WITHOUT UAC,use at system Start and in batch files (use task Scheder)”“启动程序,不带 UAC,在系统启动和批处理文件中都很有用(使用任务调度器)”
@Echo Off
REM Executes a command in an elevated PowerShell window and captures/displays output
REM Note that any file paths must be fully qualified!
REM Example: elevate myAdminCommand -myArg1 -myArg2 someValue
if "%1"=="" (
REM If no command is passed, simply open an elevated PowerShell window.
PowerShell -Command "& {Start-Process PowerShell.exe -Wait -Verb RunAs}"
) ELSE (
REM Copy command+arguments (passed as a parameter) into a ps1 file
REM Start PowerShell with Elevated access (prompting UAC confirmation)
REM and run the ps1 file
REM then close elevated window when finished
REM Output captured results
IF EXIST %temp%\trans.txt del %temp%\trans.txt
Echo %* ^> %temp%\trans.txt *^>^&1 > %temp%\tmp.ps1
Echo $error[0] ^| Add-Content %temp%\trans.txt -Encoding Default >> %temp%\tmp.ps1
PowerShell -Command "& {Start-Process PowerShell.exe -Wait -ArgumentList '-ExecutionPolicy Bypass -File ""%temp%\tmp.ps1""' -Verb RunAs}"
Type %temp%\trans.txt
)
@ECHO OFF
SETLOCAL EnableDelayedExpansion EnableExtensions
NET SESSION >nul 2>&1
IF %ERRORLEVEL% NEQ 0 GOTO ELEVATE
GOTO :EOF
:ELEVATE
SET this="%CD%"
SET this=!this:\=\\!
MSHTA "javascript: var shell = new ActiveXObject('shell.application'); shell.ShellExecute('CMD', '/K CD /D \"!this!\"', '', 'runas', 1);close();"
EXIT 1
将这个脚本保存为“ God.cmd”,放在你的 System32或者任何你的路径指向的地方。
如果你在 e 中打开一个 cmd: mypicture 并键入 God
它会要求您提供证书,然后把您放回管理员所在的位置。
C:\Users\Someone>net session
System error 5 has occurred.
Access is denied.
C:\Users\Someone>gsudo
C:\Users\Someone# net session
There are no entries in the list.