Computing.Net > Forums > Programming > Tell a .bat to close itself?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Tell a .bat to close itself?

Reply to Message Icon

Name: DrunkenSensei91
Date: November 6, 2008 at 03:49:39 Pacific
OS: x
CPU/Ram: x
Product: x
Comment:

Hi,

I've made a batch script which has a list of commands to do. One of them is to close explorer.exe which it says access denied to... but it works anyway lol. Only problem is now it ignores my exit command at the end of the batch and the window doesnt close... how can i force it to close?

Thanks =]



Sponsored Link
Ads by Google

Response Number 1
Name: Holla
Date: November 6, 2008 at 04:26:38 Pacific
Reply:

DrunkenSensei91,
You did not mention the OS you are running.
I presume it is XP or lower.
I think you just need to click on the system menu at left top of command window and chose "close on exit" somewhere....
I think you can do the same by right clicking on the batch file's icon too; I am not too sure.

I have Vista now and cant check this now as they have removed it in Vista.

--
Holla.


0

Response Number 2
Name: Holla
Date: November 6, 2008 at 04:34:07 Pacific
Reply:

Dear DrunkenSense,

I have read somewhere saying if your command prompt does not have anything on display, windows closes it, regardless of the setting of "close on exit". Try adding this at the end of the batch file:


@Echo Off
CLS

--
Holla.


0

Response Number 3
Name: DrunkenSensei91
Date: November 6, 2008 at 06:22:22 Pacific
Reply:

Windows XP yes. I don't want to have to click the properties of command prompt or anything, i need it to be an automated thing because i will be distributing this amongst peers of a network. I tried adding @echo off and cls to the batch but it didn't close the window, it still said "End process failed for explorer: Access is denied." But it actually ends explorer and ignores my exit command...?


0

Response Number 4
Name: klint
Date: November 6, 2008 at 07:40:09 Pacific
Reply:

What command are you using to close Explorer? Can you show us this command up to the end of your batch file where you call exit?

"But it actually ends explorer and ignores my exit command" -- I bet it doesn't actually end the process. Just because the Explorer windows disappear, doesn't mean the process has ended. Does it show in the Processes tab in Task Manager?


0

Response Number 5
Name: DrunkenSensei91
Date: November 6, 2008 at 07:44:45 Pacific
Reply:

@ECHO OFF
tskill explorer
cd %windir%
explorer.exe
cls
exit

I know this script looks weird as hell to you all but it has a purpose which works perfectly fine... just leaves behind the access denied. If i don't re run explorer like i do in that script it will do it itself but i do it to get it done quicker.


0

Related Posts

See More



Response Number 6
Name: klint
Date: November 6, 2008 at 09:05:27 Pacific
Reply:

Aha! There you are, you've called explorer.exe which makes your batch file pause until explorer.exe exits...

You need to say START explorer.exe. Then your batch file will carry on until it exits.


0

Response Number 7
Name: klint
Date: November 6, 2008 at 09:10:50 Pacific
Reply:

By the way, I've just noticed another problem. When you call explorer.exe, presumably to start a new explorer process, it notices that there is already an explorer process running (it's the one that's in the process of getting killed, but the new process doesn't know that.)

The default behaviour for explorer is to hand over control to an existing explorer process. So your new explorer process tries to hand over control to the dying process, which may get a bit tricky, and may be the reason you are getting that weird error message. I would say the best thing is NOT to re-start explorer, but to let it restart itself. It will re-start once the old process has completely died, which is the cleanest thing to do, and which takes a little more time.


0

Response Number 8
Name: DrunkenSensei91
Date: November 6, 2008 at 18:24:16 Pacific
Reply:

This is the only way my script works... i know it sounds weird but for what i'm having it do it will only work this way. Can i stop it from pausing or whatever? The application is working perfectly i just need to remove the command prompt after it finishes the commands automatically... Instead of hanging on the screen. Help please?


0

Response Number 9
Name: Holla
Date: November 6, 2008 at 22:54:41 Pacific
Reply:

Just try putting an @ before cls.

Dont ask me why.

--
Holla.


0

Response Number 10
Name: klint
Date: November 7, 2008 at 06:36:37 Pacific
Reply:

As per my earlier post, to stop it from pausing put this:

START explorer.exe

instead of:

explorer.exe


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Tell a .bat to close itself?

Compile a .BAT to a .EXE www.computing.net/answers/programming/compile-a-bat-to-a-exe/17224.html

VB EXE prog to launch a BAT and EXE www.computing.net/answers/programming/vb-exe-prog-to-launch-a-bat-and-exe/10949.html

passing parameters to a bat file www.computing.net/answers/programming/passing-parameters-to-a-bat-file-/13094.html