Writing 2 batch files into 1

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
perulo
Posts: 1
Joined: 02 Jul 2012 03:48

Writing 2 batch files into 1

#1 Post by perulo » 02 Jul 2012 03:53

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 :)

YaYaBinks3
Posts: 7
Joined: 04 Aug 2012 10:02

Re: Writing 2 batch files into 1

#2 Post by YaYaBinks3 » 06 Aug 2012 01:29

Hi. Use START:

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

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

Post Reply