mkumars
mkumars

Reputation: 533

Running Portable Exe file through batch file

I have created a batch file which runs multiple commands in the Windows command prompt, which is working just fine, however, I want to run a portable exe file through the same batch file as well. E.g. if I transfer the zip file to another computer, all I would like to do is run the batch file and that portable exe would run along with the other commands as well

:start
cls
color 1A
cls
@echo off
echo. 
echo. 
echo.
echo ********************************************
echo ************* Test Program **************
echo ********************************************
echo. 
echo. 
echo.
echo 01) System information
echo 02) Ping
echo 03) IP configuration
echo 04) Verify Drivers
echo 05) Driver List 
echo 06) Get Serial Number 
echo 07) Disk Defragmentation 
echo 08) DiskPart 
echo 09) Repair Load Preferences 
echo 10) Run CCleaner 
echo.
REM This is a test program 
REM echo This is a Test Program 
set /pnum= Type the corresponding number to perform an operation: 
if %num%==01 (
cls
systeminfo 
)
if %num%==02 (
cls
ping www.google.com
)
if %num%==03 (
cls
ipconfig /all
)
if %num%==04 (
cls
verifier
)
if %num%==05 (
cls
driverquery
)
if %num%==06 (
cls
wmic bios get serialnumber
)
if %num%==07 (
defrag c: /a 
pause
cls
)
if %num%==08 (
diskpart 
pause
cls
)
if %num%==09 (
cls
lodctr /r /f
echo.
pause
)   
if %num%==10 (
cls 
C:\Users\kumar\Desktop\CCleaner.exe
echo.
pause)

    set /p choice="Do you want to restart? Press 'Y' to continue, or any other key to exit: "
if '%choice%'=='y' goto start

So for example in the last condition I am running CCleaner which is on the Desktop at the moment, but if i copy a zip file which consists of the BAT File and the CCleaner.exe how would i enable it to run on another PC after copying?

Any help would be appreciated.

Upvotes: 0

Views: 1922

Answers (3)

This could be useful in the case your app uses some system variables (e.g. PATH) and you might want to reassign them locally before starting the application. The provided .exe will pass control to a .bat where you can do this and much more. At the end of this .bat run the App.exe

Upvotes: 0

lit
lit

Reputation: 16256

If the "portable" directory will contain all executable files, another way is to make the location of the .bat script the current working directory.

@ECHO OFF
PUSHD "%~dp0"

: do things, the directory of the .bat script is the current directory

POPD
EXIT /B 0

Upvotes: 2

Stephan
Stephan

Reputation: 56188

place your tools into the same folder as the batchfile and instead of

C:\Users\kumar\Desktop\CCleaner.exe

do

%~dp0\CCleaner.exe

%~dp0 is Drive and Path of your batchfile.

You may also put your tools into a subdir (tools) and:

%~dp0\tools\CCleaner.exe

Upvotes: 0

Related Questions