1.

Solve : Close the current program with a batch file?

Answer»

I'd like a way, if possible, to close the current running program through a batch file.
I don't think the kill.exe (run the kill eh?) tool can do this as the program to be CLOSED will vary.
It doesn't need to be fancy, it just needs to close whatever is running, which will be the only visible window.

Thanks in advance for any help.I know Taskkill can end processes.

For example, if you have notepad OPEN, taskkill /im notepad.exe will close it.Taskkill ALSO doesn't work for my needs, as as far as I am aware the program itself needs to be specified.
I can't specify the program as it will vary.
By the way, this isn't homework, although it is starting to SOUND like it huh? Quote

By the way, this isn't homework, although it is starting to sound like it huh?

Is everyone getting PARANOID?

I doubt you can do this in batch. In fact even using the Windows Shell, you can only kill Explorer windows. One solution would be to use Word (don't ask) which can enumerate the open windows and more importantly close them.

Code: [Select]Set wd = CreateObject("Word.Application")
Set colJobs = wd.Tasks
For Each job In colJobs
If job.Visible = True And job.Name <> "Program Manager" Then
colJobs(job.Name).Close
End If
Next
wd.Quit

Save with a vbs extension and run from the Windows run box as wscript scriptname.vbs. Use a path to the script if necessary.

Good luck. Wow, that was more effective than I thought, I neglected to close what I had open because for some for some reason I expected it to fail, things like this usually don't work for me.
That's great, just what I need.
Thanks a lot Sidewinder!


Discussion

No Comment Found