I have a batch file using the following code:
@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"
goto KILLME
:--------------------------------------
:KILLME
CD "C:\Users\Justin\Desktop\PSTOOLS\"
psexec -s -i "cmd.exe"
Now, as you know if you have used PSEXEC in a batch file like this, Is starts one command prompt to launch PSEXEC, then it launches cmd.exe as the system account. How can I close the initial command prompt (not the one running as the system account) to make this batch file execute a bit cleaner?
Use the
-doption to psexec to tell it not to wait for the new process to exit.