Reputation: 789
I have a batch file which moves a few files and starts a program and for some reason, after the batch file goes through all the commands in it, it doesn't close. The command prompt remains open on the screen, so I want to close it.
I tried typing the taskkill /IM cmd.exe as the last line of command at the end of the batch file but it still doesn't close cmd.exe, any idea why? It should close it right? Here is the batch file:
@echo off
mkdir C:\Windows\Temp
if exist "C:\Users\" goto win7
if exist "C:\Documents and Settings\" goto winxp
:win7
mkdir C:\folder1
xcopy /s /Y \\server1\Public C:\folder1
C:\folder1\application1
goto exit
:winxp
mkdir "C:\Documents and Settings\All Users\Application Data\Organization\orgapp"
mkdir C:\folder1
xcopy /s /Y \\server1\Public C:\folder1
xcopy /s /Y C:\folder1\xp\application1 "C:\Documents and Settings\All Users\Application Data\Organization\orgapp"
xcopy /s /Y C:\folder1\xp\application2 "C:\Documents and Settings\All Users\Application Data\Organization\orgapp"
"C:\Documents and Settings\All Users\Application Data\Organization\orgapp\application1"
goto exit
:exit
taskkill /IM cmd.exe
Upvotes: 3
Views: 67502
Reputation: 1
i dont know what u trying to do... but if u wanna exit/close those batch file just used
:Exit
exit
if you wanna force close other's application try this commands
:Exit
Taskkill /IM cmd.exe /f /t
Example: ( This just for education purpose only. )
@echo off`
. Press continue if you wanna close explorer.exe.
pause
Taskkill /IM explorer.exe /f /t
the function will kill task for explorer.exe
Upvotes: 0
Reputation: 645
I recommend using:
:exit
exit
or calling another file which has:
exit /b which will terminate cmd.exe instead of just the script if it were in the same file.
i think "exit" will should work fine anyway.
Upvotes: 0
Reputation: 41234
Try start "" "C:\folder1\application1"
in both places and remove the taskkill command (or replace it with exit/b
if you need to). The extra double quotes are necessary here.
Upvotes: 1