Windows batch file start another batch with elevated rights -
i want batch file start batch file elevated (admin) rights without having accept prompt. have user (called "user") admin rights, if try:
runas /savecred /user:user "program.bat"
the rights won't elevated. if try:
runas /savecred /user:administrator "program.bat"
and enter password of "user" says: unknown user or wrong passphrase.
so: have elevate rights "user"-account?
this might bit overkill if second batch file supposed always run administrator paste following code @ start of it:
@echo off & setlocal enabledelayedexpansion if "%processor_architecture%" equ "amd64" ( >nul 2>&1 "%systemroot%\syswow64\cacls.exe" "%systemroot%\syswow64\config\system" ) else ( >nul 2>&1 "%systemroot%\system32\cacls.exe" "%systemroot%\system32\config\system" ) if '%errorlevel%' neq '0' ( echo asking administrative rights goto uac ) else ( goto adm ) :uac echo set uac = createobject^("shell.application"^) > "%temp%\uac.vbs" set params = %*:"="" echo uac.shellexecute "cmd.exe", "/c ""%~s0"" %params%", "", "runas", 1 >> "%temp%\uac.vbs" "%temp%\uac.vbs" del "%temp%\uac.vbs" cls echo did not administrative rights exit :adm pushd "%cd%" cd /d "%~dp0" cls echo got administrative rights :: :: code here ::
edit: won't show prompt , give admin rights when disable uac.
Comments
Post a Comment