Launch Batch Scripts as Administrator (with GUI UAC prompt)
Imagine you write a batch script(.bat) and you converted it to an executable file (.exe), then you try to run it, it says access denied.
You could add the runas command to your batch script and have to type the admin password at the prompt.
OR
You should put into your batch script some additional batch code (as shown below) that launches the batch script or created executable (.exe) file as an administrator GUI UAC prompt, where we can select either yes or no options, rather than have to type in the admin password on the prompt.
Thank you Eneerge @ https://sites.google.com/site/eneerge/scripts/batchgotadmin
Solved, tested and it works, find script below, copy and paste, then run.
@echo off
REM Launch Batch Scripts as Administrator (with GUI UAC prompt)
:: BatchGotAdmin
:-------------------------------------
REM --> Check for permissions
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"
)
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"
set params = %*:"=""
echo UAC.ShellExecute "cmd.exe", "/c ""%~s0"" %params%", "", "runas", 1 >>
"%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
del "%temp%\getadmin.vbs"
exit /B
:gotAdmin
pushd "%CD%"
CD /D "%~dp0"
:--------------------------------------
REM <YOUR BATCH SCRIPT HERE>
@echo off
REM Launch Batch Scripts as Administrator (with GUI UAC prompt)
:: BatchGotAdmin
:-------------------------------------
REM --> Check for permissions
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"
)
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"
set params = %*:"=""
echo UAC.ShellExecute "cmd.exe", "/c ""%~s0"" %params%", "", "runas", 1 >>
"%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
del "%temp%\getadmin.vbs"
exit /B
:gotAdmin
pushd "%CD%"
CD /D "%~dp0"
:--------------------------------------
REM <YOUR BATCH SCRIPT HERE>
Stackover Source: http://stackoverflow.com/questions/1894967/how-to-request-administrator-access-inside-a-batch-file
Wao, What a great Post it is. Just amazing to know these all things. We have to make the blogging easier with these tricks. Thanks a lot sir. Visit here PayPal gift card code generator
ReplyDelete
ReplyDeleteThis is very informative and interesting for those who are interested in blogging field.
Click this link for interacting Hd wallpapers for android