[Not Question] How to close hanged cmd windows after EXE run

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

[Not Question] How to close hanged cmd windows after EXE run

#1 Post by abc0502 » 02 Jan 2013 07:41

I was making a Batch file to disable some services and processes before running an online game to reduce the memory and cpu.

After disabling the avgnt.exe and the networx.exe applications and re-starting them the problem happens, when starting any one of them the batch stop after starting the first and doesn't continue.

I found a way to work around this after along tries and errors and though some one might need it.

1> Create a Function.
This function will create separate batch files for every command.
2> And it must contain a main two batch file:
1) kill.bat : that contain a command to kill the cmd.exe file.
2) run.bat : that contain a command to run what batch files you will ever create and the run command for the kill.bat file.


and as an example applaied to the previous two EXE files:

Code: Select all

@echo off
:: here you will put all your commands and
:: call the function in right time then start the run.bat
:: For Example
IF "1" == "1" (
    Call :Do
    start "" "%temp%\run.bat"
)
:: remember to add the kill.bat in the run.bat
Exit /B

:Do
:: <<<1st application>>>
(
Echo "%programfiles%\Avira\AntiVir Desktop\avgnt.exe"
)>"%temp%\1.bat"
:: <<<2nd application>>>
(
Echo "%programfiles%\networx\networx.exe"
)>"%temp%\2.bat"
:: <<<Kill batch file>>>
(
Echo Ping localhost -n 13 >nul
Echo Taskkill /F /IM:cmd.exe
)>"%temp%\kill.bat"
:: <<<Run batchfile>>>
(
Echo start "1st EXE" "%temp%\1.bat"
Echo start "2nd EXE" "%temp%\2.bat"
Echo start "Kill Batch" "%temp%\kill.bat"
)>"%temp%\run.bat"
GOTO :EOF


The kill.bat will kill all cmd.exe processes which is used to run the original applications "avgnt.exe" and "networx.exe" so when these application starts even after the kill.bat was finished it will not be closed unless they finished from starting.

> I tried using the cmd.exe /c command but it didn't work.
> Also note that you have to use the start command to start separate CMD windows for each command that hang and not executing what ever commands after it.
> And you must use the one > to create the file so you don't have to delete them after every execution of the batch as they will be overwritten each time.
> In normal start of the windows the -n in the ping command should equal seconds but when closing all other processors and services i think it becomes milliseconds as they executing the command very fast.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: [Not Question] How to close hanged cmd windows after EXE

#2 Post by abc0502 » 02 Jan 2013 08:13

Also if you wanted to set the priority of a process that start later from another process that you cant use the start command to do that, just add a delay command then run this command:

Code: Select all

wmic process where name="avgnt.exe" CALL setpriority 32768

And these are the priority numbers:
Idle: 64
Below Normal: 16384
Normal: 32
Above Normal: 32768
High Priority: 128
Real Time: 256


Source

Post Reply