Need Batch File to close a Window.. NOT the batch window
AFAIK that's not possible with 'pure' batch - you'd need to use either a 3rd party tool or use powershell [or some other way to reference Win API].
If I understood you correctly and the window you want to close is a kind of a control panel which redefines Window close message than this should work (as run from cmd and assuming there is only one instance of the process):
powershell (ps MySystemManager).CloseMainWindow()
This command acts as if you'd clicked 'close' (X) button
I have tested it with xampp control panel (powershell (ps xampp-control).CloseMainWindow()
), your mileage may vary
Related videos on Youtube
batchKevin
Updated on September 18, 2022Comments
-
batchKevin over 1 year
Complete novice here so please forgive if the answer is obvious.
I have a batch file that does the following.
Starts program 1 Waits 3 seconds (I have to click a button on program 1 after it opens) Then program 2 starts.
My problem is that program 1 just needs to run in the background.... No window needed after the first 3 seconds.
Normally, I start the batch file, program 1 starts. I click the button to start a service.
Three seconds the second program starts.
I then have to go back to program 1 and click the X in top right of window to close it. I'd like for the WINDOW on program one to close automatically after 3 seconds (but the program itself cannot be killed).
Suggestions?
@echo off start C:\Folder\To\MySystemManager.exe TIMEOUT 3 start "" "C:\Program Files (x86)\CustomProgram\CustomProgram.exe" exit
-
LPChip over 9 yearsPlease post the content of your batch file so we can help troubleshoot.
-
vembutech over 9 yearsCan you try the delay options in Windows Task Scheduler and check your results. You can make a batch file to run at a particular delay on an action triggered in your machine. You need to think little and apply a sort solution that can make some delay to start and close the program.
-
batchKevin over 9 yearsPosted code. Not sure I follow you on the need for a delay. I have that. What I need is a command to essentially close a Window (but not the task/program" that has the title "MySystemManager" or something along that line.... I think.
-
JosefZ over 9 yearsNot sure why you do not provide obligatory
"title"
parameter in the firststart
? Try the same as in second use:start "" C:\Folder\To\MySystemManager.exe
-
-
batchKevin over 9 yearsYou are brilliant! I know I'm a novice but I have done dozens of Google searches and have found nothing that explained how to do this. I didn't even know you could enable power shell in a .bat file. Anyway, thanks a lot. I really appreciate it.