Windows 7 UAC Elevation - Issues with BATCH files

So I am trying to write some batch menus that uninstall, install, add registy entries, etc. by a batch menu. I am running into elevation issues.  I found a way to run elevation and prompts but then the issues I run into is that when elevation is accepted it calls the batch menu but it runs and closes.

The first file determines if the computer is 32 or 64 bit then launches the appropriate menu.

Set RegQry=HKLM\Hardware\Description\System\CentralProcessor\0
 
REG.exe Query %RegQry% > c:\DLI\checkOS.txt
 
Find /i "x86" < c:\DLI\CheckOS.txt > c:\DLI\StringCheck.txt
 
If %ERRORLEVEL% == 0 (
   

z:\DLI-SCRIPTS\DLI-MENU-32b.bat

) ELSE (
    Echo "This is 64 Bit Operating System"

    
z:\DLI-SCRIPTS\DLI-MENU-64b.bat

)

exit

Open in new window


@ECHO OFF
cls
REM.-- Prepare the Command Processor
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION

:menuLOOP
echo.
echo.= Menu (64 BIT)=================================================
echo.
for /f "tokens=1,2,* delims=_ " %%A in ('"findstr /b /c:":menu_" "%~f0""') do echo.  %%B  %%C
set choice=
echo.&set /p choice=Make a choice or hit ENTER to quit: ||GOTO:EOF
echo.&call:menu_%choice%
GOTO:menuLOOP

::-----------------------------------------------------------
:: menu functions follow below here
::-----------------------------------------------------------

:menu_A   ** UNINSTALL INFOR SOFTWARE **
CALL Z:\DLI-SCRIPTS\DLI-MENU-INFORUNINSTALL-64b.bat
GOTO:EOF

:menu_

:menu_1   INSTALL INFOR SOFTWARE
CALL Z:\DLI-SCRIPTS\DLI-MENU-1INSTALL-64b.bat
GOTO:EOF


:menu_1B   INSTALL WINDOWS SOFTWARE
CALL Z:\DLI-SCRIPTS\DLI-MENU-1BINSTALL-64b.bat
GOTO:EOF


:menu_

:menu_2   UNINSTALL SOFTWARE
copy /y "z:\DLI-SCRIPTS\REQUIRED-FILES\myuninst\myuninst.exe" "c:\dli\myuninst.exe"
copy /y "z:\DLI-SCRIPTS\REQUIRED-FILES\myuninst\myuninst.chm" "c:\dli\myuninst.chm"
c:\dli\myuninst.exe


GOTO:EOF

:menu_

:menu_3   REGISTRY TWEAKS
CALL Z:\DLI-SCRIPTS\DLI-MENU-3REGISTRY-64b.bat
GOTO:EOF

:menu_

:menu_4   AUDIT PC
START C:\WINDOWS\AUDIT.BAT
GOTO:EOF

:menu_

:menu_5   EMPTY
echo.Have some fun by adding some more code right here
GOTO:EOF

:menu_

:menu_6   LICENSE KEY TEXT FILE
NOTEPAD.EXE Z:\UTILSCD\STATICFILES\LICENSE_KEYS_MICROSOFT.TXT
GOTO:EOF

:menu_
:menu_



:menu_AL AUTOLOGON FOR ADMINISTRATOR (SET)
copy /y "Z:\DLI-SCRIPTS\AUTOLOGON\Autologon.exe" "c:\windows\autologon.exe"
Z:\DLI-SCRIPTS\AUTOLOGON\SET-AUTOLOGIN.vbs
GOTO:EOF

:menu_AR AUTOLOGON FOR ADMINISTRATOR (REMOVE)
copy /y "Z:\DLI-SCRIPTS\AUTOLOGON\Autologon.exe" "c:\windows\autologon.exe"
Z:\DLI-SCRIPTS\AUTOLOGON\REMOVE-AUTOLOGIN.vbs
GOTO:EOF


:menu_


:menu_
:menu_RB REBOOT THIS COMPUTER
START shutdown -f -r -t 2
GOTO:EOF

:menu_




:menu_99   CLEAR SCREEN
cls
GOTO:EOF

Open in new window




This is the code I used to elevate and it worked until I tried to call the other batch file

:::::::::::::::::::::::::::::::::::::::::
:: Automatically check & get admin rights
:::::::::::::::::::::::::::::::::::::::::
@echo off
CLS 
ECHO.
ECHO =============================
ECHO Running Admin shell
ECHO =============================

:checkPrivileges 
NET FILE 1>NUL 2>NUL
if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges ) 

:getPrivileges 
if '%1'=='ELEV' (shift & goto gotPrivileges)  
ECHO. 
ECHO **************************************
ECHO Invoking UAC for Privilege Escalation 
ECHO **************************************

setlocal DisableDelayedExpansion
set "batchPath=%~0"
setlocal EnableDelayedExpansion
ECHO Set UAC = CreateObject^("Shell.Application"^) > "%temp%\OEgetPrivileges.vbs" 
ECHO UAC.ShellExecute "!batchPath!", "ELEV", "", "runas", 1 >> "%temp%\OEgetPrivileges.vbs" 
"%temp%\OEgetPrivileges.vbs" 
exit /B 

:gotPrivileges 
::::::::::::::::::::::::::::
:START
::::::::::::::::::::::::::::
setlocal & pushd .

call z:\dli-scripts\menu-64b_e.bat

Open in new window


Any help is appreciated.
LVL 24
DMTechGrooupAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RobSampsonCommented:
Hi, not too sure, but I'd say it's most likely got to do with the fact you're using mapped drive paths.  I would change each Z: reference to the UNC path, such as
\\server\share

since, when you run with another user account (or different token), you won't have the mapped drive available.

Regards,

Rob.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.