Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Batch to close window  (Read 2165 times)

0 Members and 1 Guest are viewing this topic.

eagle13

  • Guest
Batch to close window
« on: August 31, 2006, 02:12:44 AM »
Hi

I am a total batch n00b so be easy on me!
I have a batch file that will open some mapped drives on a computer.

The format is simple:
start G:\
start H:\
start I:\
start J:\

The batch works ok so far, but I am left with these windows open. Is there some more code I can put on the end that will close the windows and return to a clean desktop?

uli_glueck

  • Guest
Re: Batch to close window
« Reply #1 on: August 31, 2006, 04:36:10 AM »
"exit" closes cmd windows

uli

eagle13

  • Guest
Re: Batch to close window
« Reply #2 on: August 31, 2006, 04:44:18 AM »
I don't need to close the cmd window, that closes automatically.

I mean I need to close the Explorer window, the one I opened with the batch file in the first place!

in other words, G:\ window contents is now open, I want to close it with a batch command.

uli_glueck

  • Guest
Re: Batch to close window
« Reply #3 on: August 31, 2006, 01:21:30 PM »
Oh.
Killing the explorer task might be an option. "kill".
Why do you open the explorer? Is there no way to avoid it?
Dumb question I know, but...

uli

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: Batch to close window
« Reply #4 on: August 31, 2006, 02:10:31 PM »
You would need to send keystrokes to each of the open windows. Batch coding cannot do this, but VBScript can:

Code: [Select]
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.AppActivate "[highlight]Window Title[/highlight]"
WScript.Sleep 100
WshShell.SendKeys "{F4}"

The highlighted area contains the Window title NOT the executing program name which presumably is explorer. You can repeat the last three statements as needed.

After saving the script with a VBS extension, run with cscript scriptname.vbs

There is also a program called AutoIt that can be helpful in this situation but VBScript is already installed on your machine.

 8-)

The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein