Start another .bat in .bat with wait option

February 23, 2015 at 05:54:17
Specs: Windows 8.1
I have little problem, because I must in my first .bat start second .bat with admin pass. There I have problem, because when i use start /wait to start second .bat and all operations finish second cmd window doesn't closing and view directory. Or when I use this method in second bat, it wants admin pass whereupon open thierd cmd window and in second view directory.

First bat (test1.bat):

@ECHO OFF
start /wait test2.bat
pause

Second bat (test2.bat)

@echo off
:: BatchGotAdmin (Run as Admin code starts)
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"
call notepad.exe
pause

Picture with problem:
Click


See More: Start another .bat in .bat with wait option

Report •

#1
February 24, 2015 at 01:08:37
Seems like you'll be better off if you:

CALL test2.bat

[I never heard of STARTing a bat, but hey...]

=====================

M2 Get custom script or take private lessons


Report •

#2
March 1, 2015 at 23:04:36
Call isn't working. I check it firstly.

First batch (test1.bat) go further


Report •

#3
March 2, 2015 at 20:14:54
I don't know why.

Post your script.

=====================

M2 Get custom script or take private lessons


Report •

Related Solutions

#4
March 3, 2015 at 08:48:01
first bat:
@ECHO OFF
echo first bat
call test2.bat

echo poszło dalej
pause

second bat:

@echo off
echo check mark
    :: BatchGotAdmin (Run as Admin code starts)
    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"

echo second bat
call notepad.exe
pause


Report •

#5
March 3, 2015 at 19:11:21
I only got as far as the cacls and got this:

The Cacls command can be run only on disk drives that use the NTFS file system.

Hopefully somebody will jump in here with help.

=====================

M2 Get custom script or take private lessons


Report •

#6
March 26, 2015 at 00:32:55
Somebody have a solution?

Report •

Ask Question