4

In a Windows batch file, or in the Command Prompt, what's the difference between calling start mspaint, for example, and mspaint? They appear to do exactly the same thing.

Another example, where all 4 cases appear to do the same thing. Can you please help me understand what are the subtle differences, if any?

  1. taskmgr
  2. C:\Windows\System32\Taskmgr.exe
  3. start taskmgr
  4. start C:\Windows\System32\Taskmgr.exe

Follow-up: it looks like start opens a separate background command prompt to run the program you write after it (source: https://technet.microsoft.com/en-us/library/cc770297(v=ws.11).aspx). Is this the same as Linux's myApp & format--where you have the & suffix?

Gabriel Staples
  • 36,492
  • 15
  • 194
  • 265
  • 2
    To `&` yes it is. In Windows `&` separates multiple lines on one line. `dir c:\ & dir d:\ `. See my summary of characters here http://stackoverflow.com/questions/31820569/trouble-with-renaming-folders-and-sub-folders-using-batch –  Oct 07 '16 at 20:56

2 Answers2

2

Starting a Program

See start /? and call /? for help on all three ways.

Specify a program name

c:\windows\notepad.exe

In a batch file the batch will wait for the program to exit. When typed the command prompt does not wait for graphical programs to exit.

If the program is a batch file control is transferred and the rest of the calling batch file is not executed.

Use Start command

start "" c:\windows\notepad.exe

Start starts a program and does not wait. Console programs start in a new window. Using the /b switch forces console programs into the same window, which negates the main purpose of Start.

Start uses the Windows graphical shell - same as typing in WinKey + R (Run dialog). Try

start shell:cache

Also note the first set of quotes, if any, MUST be the window title.

Use Call command

Call is used to start batch files and wait for them to exit and continue the current batch file.


With Reference to Start and just typing a program name.

Help Windows Find Programs and Documents

Programs and documents can be added to the registry so typing their name without their path in the Start - Run dialog box or shortcut enables Windows to find them.

REGEDIT4
;The bolded name below is the name of the document or program, <filename>.<file extension> 

[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\App Paths\IE.txt]

;The @ means the path to the file is assigned to the default value for the key.
;The whole path in enclosed in a quotation mark ".

@="\"C:\\Program Files\\Internet Explorer\\IE.txt\""

;Optional Parameters. The semicolon means don't process the line. Remove it if you want to put it in the registry

;Informs the shell that the program accepts URLs.

;"useURL"="1"

;Sets the path that a program will use as its' default directory. This is commented out.

;"Path"="C:\\Program Files\\Microsoft Office\\Office\\"

For a technical discussion.

CMD preprocesses commands and finds the file then calls CreateProcess. Start - Run dialog or the Start command uses ShellExecuteEx which eventually calls CreateProcess.

This is CreateProcess rules - note CMD provides full paths to CreateProcess. https://msdn.microsoft.com/en-us/library/ms682425

1.The directory from which the application loaded.

2.The current directory for the parent process.

3.The 32-bit Windows system directory. Use the GetSystemDirectory function to get the path of this directory.

  1. The 16-bit Windows system directory. There is no function that obtains the path of this directory, but it is searched. The name of this directory is System.

5.The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.

6.The directories that are listed in the PATH environment variable. Note that this function does not search the per-application path specified by the App Paths registry key. To include this per-application path in the search sequence, use the ShellExecute function.

ShellExecuteEx is here https://msdn.microsoft.com/en-us/library/bb759784(v=vs.85).aspx

CMD preprocessing is available on my Skydrive - originally from MS web site but no more. See Windows NT Command Shell Ch 2 https://1drv.ms/f/s!AvqkaKIXzvDieQFjUcKneSZhDjw

Community
  • 1
  • 1
1

you need to call start application when you want the application to launch and return immediately to the command shell for further commands.

(on Linux, closest equivalent of start is the & suffix)

Some commands have the ability to do that without start prefix. That's what you're experiencing.

On the other hand, if you want an application returning immediately to "block" the shell, prefix by cmd /c

Try cmd /c taskmgr for instance, you'll see it blocks the command window until you quit it.

About the question about taskmgr, the 3 possibilities amount to the same result:

  • taskmgr is in system path: with or without full path the system finds it
  • taskmgr returns to the command window immediately. In that case, start is redundant.
Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
  • Ok, so it looks like `start` opens a separate command prompt window to run an application. See here: https://technet.microsoft.com/en-us/library/cc770297(v=ws.11).aspx. Does that mean every time I click on a shortcut to a program in the Windows GUI start menu there is a command prompt running in the background for that program? – Gabriel Staples Oct 07 '16 at 18:19
  • Follow up question: does that mean the Windows `start` prefix is the same as the Linux `&` suffix? Ex: in Linux: `leafpad &` is like in Windows: `start leafpad` (if leafpad were a Windows program)? – Gabriel Staples Oct 07 '16 at 18:20
  • 1
    some applications are "windows only" applications, means that they won't open a console. Only "console" apps open a console. For instance, build some code with `gcc` & the `-mwindows` switch you won't get the console. – Jean-François Fabre Oct 07 '16 at 18:23