0

as the title suggests I'm trying to create a batch file to start some programs whenever I want. It has been a while since I've dealt with this so I'm rusty.

My current lines are

@echo off 

start "" "TaskMgr" 
start "" "path to exe1" /wait 
start "" "path to exe2" /wait

As I've found if I want to start them one AFTER another and not in parallel I need to use /wait. What I'm unsure of is the task manager line. I've found that you can start it with simple TaskMgr (which doesnt allow for any other line reading in the file and keeps command prompt up) and since I'm not using the path to task manager exe I was wondering if this is the correct way to do this.

If I have somewrong understanding comments are welcome.

P.S./Bonus: On unrelated note, how does one paste multiple code lines to be displayed as code here so that one wouldnt need to spam 4 spaces at the beggining of each line? (which might ruin the tabulation if not attentive enough)

NulisDefo
  • 325
  • 2
  • 7
  • 19
  • The four spaces _is_ the way to mark a code block. – Jeff Zeitlin Dec 19 '17 at 16:35
  • what i meant was just maybe there is an alternative to, for example, posting a 10 lines of code and then going to the beggining of the line and inputting 4 spaces 10 times (1 for each row) :) – NulisDefo Dec 19 '17 at 16:39
  • 1
    Paste your ten lines, then highlight them all, and click on the toolbar icon `{ }`. – Jeff Zeitlin Dec 19 '17 at 16:49
  • 1
    `taskmgr.exe` can be started without full path as `C:\Windows\system32` is in your path. Type `set` to verify. You can use `C:\Windows\System32\Taskmgr.exe` or `C:\Windows\SysWOW64\Taskmgr.exe` instead if you want. – Michael S. Dec 19 '17 at 16:58
  • What did @JeffZeitlin get for his bonus? The `/Wait` option for `Start` may not work, especially if your `.exe` is a stub/launches another executable. – Compo Dec 19 '17 at 17:23
  • @NulisDefo Read [What is the reason for '…' is not recognized as an internal or external command, operable program or batch file?](https://stackoverflow.com/a/41461002/3074564) to get knowledge about how Windows command interpreter `cmd.exe` processing a batch file starts an application. Run in a command prompt window `start /?` for help on this command and read answers on [Where is “START” searching for executables?](https://stackoverflow.com/a/27386403/3074564) and [How to call a batch file that is one level up from the current directory?](https://stackoverflow.com/a/24725044/3074564) – Mofi Dec 19 '17 at 18:59
  • @NulisDefo I suggest also reading Wikipedia article about [Windows Environment Variables](https://en.wikipedia.org/wiki/Environment_variable#Windows) and make use of any predefined Windows environment variable in your batch file wherever possible. Run in a command prompt window just `set` to get displayed all environment variables defined by Windows for your user account. Run `set /?` for complete help on this command listing on last page some more always defined environment variables. See also [Microsoft's command-line reference](https://technet.microsoft.com/en-us/library/cc754340.aspx). – Mofi Dec 19 '17 at 19:08

1 Answers1

1

I recommend using %SystemRoot%\System32\taskmgr.exe to avoid possible aliasing. Just using taskmgr could run taskmgr.cmd from the current directory or anywhere along the path, if it happens to find it before taskmgr.exe. It's also always the correct version of taskmgr.exe for whatever architecture you are running on.

jwdonahue
  • 6,199
  • 2
  • 21
  • 43