Page 1 of 1

Writing 2 batch files into 1

Posted: 02 Jul 2012 03:53
by perulo
I've got 2 separate batch files, the first one checks whether UAC is enabled or disabled. If enabled it calls "uac.bat".

Code: Select all

REG QUERY HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\ /v EnableLUA | FIND "0x1" >NUL && ( call uac.bat ) || ( echo Good day sir )

"uac.bat" that is located in the same folder as the previous batch file, pops-up the UAC prompt:

Code: Select all

@echo off

:: BatchGotAdmin
:-------------------------------------
REM  --> Check for permissions
>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"
    echo UAC.ShellExecute "%~s0", "", "", "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"
:--------------------------------------


I've tried using "call" command, but I'm doing something wrong because even if my UAC is disabled it still pop's up the UAC prompt as if my UAC were enabled. How to fix this?

Thanks in forward :)

Re: Writing 2 batch files into 1

Posted: 06 Aug 2012 01:29
by YaYaBinks3
Hi. Use START:

/b = run the instance of the command prompt in the same window

START /b C:\Users\User\batfile.bat