UACPrompt Batch

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jaheaga
Posts: 5
Joined: 04 Oct 2011 14:01

UACPrompt Batch

#1 Post by jaheaga » 06 Oct 2011 08:55

here is this batch file, if I opened with double click it goes ok, but if i call it from another batch file gives me an error with the vbs script it generates, I know the problem is on the

Code: Select all

echo UAC.ShellExecute %0
line but I'm not able to fix it. I dont want to right click and run as administrator.
"you should run it by calling it from another batch file"
If anyone can help me I really appreciate it



Code: Select all

@echo off

mkdir "%windir%\BatchGotAdmin"

if '%errorlevel%' == '0' (

  rmdir "%windir%\BatchGotAdmin" & goto gotAdmin

) else ( goto UACPrompt )



:UACPrompt

    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"

    echo UAC.ShellExecute %0, "", "", "runas", 1 >> "%temp%\getadmin.vbs"



    "%temp%\getadmin.vbs"

    exit /B



:gotAdmin

    if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )

    pushd "%CD%"     

    CD /D "%~dp0"

echo Pulse una tecla para deshabilitar el control de cuentas de usuario (UAC)

pause>nul

reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 0 /f

echo El control de cuentas de usuario ha sido deshabilitado

echo.

echo Ahora presione una tecla para reiniciar el equipo en 20 segundos

echo.

pause>nul

shutdown -r -f -t 20 -c "Su equipo se reiniciar  en 20 segundos para poder continuar con la asistencia, al iniciar de nuevo por favor cont ctenos inmediatamente para continuar con la reparaci¢n de su equipo"


I have a workaround, but involves using wget to retrieve the file to the %temp% dir and changing

Code: Select all

%0
to

Code: Select all

"%temp%\deshabilitarUAC.bat"
an then I call it, but I want to be able to execute it from any dir the user is working.

Thank you

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: UACPrompt Batch

#2 Post by aGerman » 07 Oct 2011 15:14

I have an idea, but I didn't test it.
Try "%~f0" instead of %0.

Regards
aGerman

Post Reply