5

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
4
  • Please post the content of your batch file so we can help troubleshoot.
    – LPChip
    Dec 31, 2014 at 20:13
  • Can 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.
    – BDRSuite
    Dec 31, 2014 at 20:19
  • Posted 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.
    – batchKevin
    Dec 31, 2014 at 20:34
  • Not sure why you do not provide obligatory "title" parameter in the first start? Try the same as in second use: start "" C:\Folder\To\MySystemManager.exe
    – JosefZ
    Dec 31, 2014 at 22:09

1 Answer 1

6

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

1
  • You 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.
    – batchKevin
    Dec 31, 2014 at 22:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .