1
votes

So I'm having Problem with closing the CMD after it runs a file ! in the code below as you can see I'm using an EXIT command but after pressing Enter the Drive name shows up and this happens again and again I have tried it without the pause to , it wont work ( I want it to pause there tho ) So i want it to exit the CMD after the user presses the Enter.

I gave a wrong .net framework number to it to test if it will run the exe file or not , it runs it but it wont close afterwards ( the cmd wont close i mean )

I have looked at these questions :

Close a batch file after running the jar file

close windows command prompt after all process completed in the batch file

cmd.exe doesn't close after starting exe

this is the problem Im having : Took a picture of the batch file when it runs which you can see on link below !

How the CMD looks when I run the batch file

Thanks in advance !

@echo off

echo " _____________________________ "
echo "|                             |"
echo "|       softRAD Loader        |"
echo "|_____________________________|"

echo " _________________________________________________________________________ "
echo "|                                                                         |"
echo "|          Checking the .Net Framework Installed on Your System           |"
echo "|_________________________________________________________________________|"


REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v5.5" /v Version
IF %errorlevel%==0 GOTO INSTALL
IF %errorlevel%==1 GOTO UNINSTALL




:INSTALL

echo " __________________________________________________________ "
echo "|                                                          |"
echo "|  .Net Framework v3.5 found , Starting the softRAD.exe    |"
echo "|----------------------------------------------------------|"
echo "|             This window closes in 3 seconds              |"
echo "|__________________________________________________________|"

echo.
ping -n 2 127.0.0.1>nul
echo "   3   "
ping -n 2 127.0.0.1>nul
echo "   2   "
ping -n 2 127.0.0.1>nul
echo "   1   "
ping -n 2 127.0.0.1>nul

GOTO end

:UNINSTALL

echo " __________________________________________________________ "
echo "|                                                          |"
echo "|  .Net Framework Not found , Attempting to Install it.    |"
echo "|----------------------------------------------------------|"
echo "|          If this Doesnt Work , Please Install the        |"
echo "|      .net Framework Included on the DVD manually.        |"
echo "|__________________> 3.5 client profile <__________________|"

cmd /K "%~dp0dotnetfx35.exe"
pause
EXIT


:end

exit
2
You do not need to use cmd.exe to launch the .Net framework install. You can just have this code on the line by itself: "%~dp0dotnetfx35.exe"Squashman

2 Answers

0
votes

Type start /?. Batch files wait for programs to exit before continuing unlike when you are typing. Start modifies the standard behaviour of starting programs. At it's most simple,

start "Title" Notepad 

Also timeout is the way to do a timeout not ping. Type timeout /?.

0
votes

The /K in cmd /K means that you keep the cmd window open after the command finishes.

To close the cmd window after the command finishes, use /C instead of /K.

From the output of cmd /?:

CMD [/A | /U] [/Q] [/D] [/E:ON | /E:OFF] [/F:ON | /F:OFF] [/V:ON | /V:OFF] [[/S] [/C | /K] string]

/C Carries out the command specified by string and then terminates
/K Carries out the command specified by string but remains