Brandon H Supervisor Posted February 11, 2015 Supervisor Share Posted February 11, 2015 Hello, I'm quite rusty in making batch files as I haven't made one in a few years so I figured I'd ask you guys for help I'm trying to create a simple batch file for Windows so that when a certain program closes the file automatically opens another program what would be a good way to set this up? would this even be possible with a simple batch file? Link to comment Share on other sites More sharing options...
0 xendrome Posted February 11, 2015 Share Posted February 11, 2015 :NOTEPAD start /wait notepad.exe || goto QUIT :NEXTITEM1 start /wait mplayer2.exe || goto QUIT :NEXTITEM2 REM You get the idea... :QUIT exit or :NOTEPAD start /wait notepad.exe IF %ERRORLEVEL% == 0 goto NEXTITEM1 else goto QUIT :NEXTITEM1 start /wait mplayer.exe IF %ERRORLEVEL% == 0 goto NEXTITEM2 else goto QUIT :NEXTITEM2 start /wait explorer.exe IF %ERRORLEVEL% == 0 goto NEXTITEM3 else goto QUIT :NEXTITEM3 REM You get the idea... :QUIT exit sc302 1 Share Link to comment Share on other sites More sharing options...
0 Top Qat Posted February 11, 2015 Share Posted February 11, 2015 Can you be a bit more specific about what you are trying to do? Link to comment Share on other sites More sharing options...
0 Brandon H Supervisor Posted February 11, 2015 Author Supervisor Share Posted February 11, 2015 at my work we have a new software phone and when you logout this new one automatically closes instead of going back to a login screen like the old one. i'd like to set up a batch file that re-opens the login screen when it closes (and before you ask. yes my work is ok with us using simple batch scripts. they have a few pre-made for us that launch all our main apps for us. just none that relaunch specific apps if they close) Link to comment Share on other sites More sharing options...
0 Top Qat Posted February 11, 2015 Share Posted February 11, 2015 What OS? does it have Powershell? Link to comment Share on other sites More sharing options...
0 Brandon H Supervisor Posted February 11, 2015 Author Supervisor Share Posted February 11, 2015 What OS? does it have Powershell? Windows 7 and no, it doesn't look like powershell is installed on the workstations Link to comment Share on other sites More sharing options...
0 Joe User Posted February 11, 2015 Share Posted February 11, 2015 If all you're doing is restarting the same app when it closes, then all you need is a simple loop. Have the batch file start at login with the task scheduler, or put it into the startup folder. persistent.bat @echo off :TOP start /WAIT app.exe GOTO TOP Now, if all you want to do is have one app and only one app only running, there are other solutions. Link to comment Share on other sites More sharing options...
0 sc302 Veteran Posted February 11, 2015 Veteran Share Posted February 11, 2015 xendrome has it right. I had something similar to Joe Users when I wanted the only thing to happen on a computer was launch remote desktop. I changed the shell from explorer.exe to the bat file. Worked great. Link to comment Share on other sites More sharing options...
0 Forjo Posted February 11, 2015 Share Posted February 11, 2015 Note that these examples are predicated on using a batch file to actually open your "software phone" for the first time. If you're looking for some kind of exit event handler, I don't think there is any support for process watching. In powershell, perhaps, but not in the normal batch processor. If, however, you're using a batch file to launch your app, the start /wait examples will work fine. -Forjo Link to comment Share on other sites More sharing options...
0 sc302 Veteran Posted February 11, 2015 Veteran Share Posted February 11, 2015 Easy enough to change the shortcut to the batch file and change the shortcut icon for the batch file to be the same as the icon of the app. Link to comment Share on other sites More sharing options...
0 Brandon H Supervisor Posted February 11, 2015 Author Supervisor Share Posted February 11, 2015 thanks guys. xendrome's example worked perfectly got it set up so it only reopens as many times as needed for my shift Link to comment Share on other sites More sharing options...
0 sc302 Veteran Posted February 11, 2015 Veteran Share Posted February 11, 2015 If you want it a bit more silent use a vb script The following will loop notepad. The only way to kill the notepad process from looping is to kill the wscript.exe process in task manager....there is no dos screen to minimize or try to hide. Copy the quoted text into a test.vbs file then double click test.vbs after you close and save. sProcessName = "notepad.exe" sComputer = "." Set oWmi = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & sComputer & "\root\cimv2") Set oShell = CreateObject("WScript.Shell") Do Set colProcessList = oWmi.ExecQuery _ ("Select * from Win32_Process Where Name = '" & sProcessName & "'") If colProcessList.Count = 0 Then 'Notepad is not running...Open Notepad oShell.Run "C:\windows\notepad.exe", 1, False End If WScript.Sleep 10 Loop Link to comment Share on other sites More sharing options...
Question
Brandon H Supervisor
Hello, I'm quite rusty in making batch files as I haven't made one in a few years so I figured I'd ask you guys for help
I'm trying to create a simple batch file for Windows so that when a certain program closes the file automatically opens another program
what would be a good way to set this up? would this even be possible with a simple batch file?
Link to comment
Share on other sites
11 answers to this question
Recommended Posts