How to launch this program from the command line? - windows

This is the program I am trying to launch from command line (Star Guard)
I opened a new command prompt process in this directory and am trying to start the Star Guard application with command line(so I can pass in command line arguments later).
However when I do so, I don't end up launching the program but I do end up launching a new command prompt process in the same directory.(output shown below) The program launches fine when I start it normally(GUI click)
Does anyone know what the issue is? I first did the ls(OSx) equivalent in Windows to make sure I had the right file path for the executable. I then used the start command to start the program along with enclosing the executable path in quotation marks to account of the spaces.

The syntax of the start command is unique, not to mention daft. If the first argument is in quotes it is interpreted as a window title.
In this case, you don't actually need to use start at all, you could just say
"Star Guard"
or
"Star Guard.exe"
If you want to use start, perhaps because you want to specify /wait for a GUI application or because you want to launch a console application in a new window, you have to include the title argument:
start "" "Star Guard.exe"
(The title argument doesn't need to actually specify a title, it just needs to be present.)

From OS/2 Warp Help
Starts an OS/2 program in another session.
The primary use for START is to automatically start programs at system startup. The
special batch file, STARTUP.CMD, allows you to do this.
To imbed redirectional signals into the command session, enclose the command and
command inputs in quotation marks.
START
"program /K /F
title" /C /B
/N
/PGM /FS /MAX
/WIN /MIN
/PM
/DOS
command
/I command
inputs
Related Commands: RUN
Enter this command without a parameter to start an OS/2 command processor.
If you use the /WIN, /FS, or /PM parameter, your program runs in the foreground session.
If you do not use one of these parameters, you can use the /F parameter to make the
program run in the foreground session.
Make sure that you specify the correct drive and path when you use the START command to
run a batch file with the STARTUP.CMD file. Also, if you plan to redirect I/O using the
START command, enclose the command and command inputs within quotation marks.
You can use START to run full-screen applications or applications running in a window
such as Presentation Manager programs.
START determines the type of application and will run it in the appropriate window or
full-screen session. However, you have the option to override the determined default by
using the /FS, /WIN, /PM, or /I parameter.
You cannot start a batch file (.CMD) with the /PM parameter.

Related

How start a program via command line after the previous process terminated itself?

I run a program like notepad.exe via command line.
After the process terminated itself after completion of task of the started application, I need to run another program via command line, for example winword.exe.
So I would like a behavior like a scheduler, waiting in background up to completion of first process and then initiate start of another process.
Can I achieve this in Windows? And if yes, how?
Batch file solutions
For the example Notepad.exe and Winword.exe the solution is quite simple with following batch file:
#echo off
%SystemRoot%\Notepad.exe
start Winword.exe
Windows command interpreter cmd.exe first starts Windows Notepad and halts execution of the batch file until Notepad.exe terminated itself which means the user
pressed Alt+F4 on keyboard, or
clicked on X symbol on right side of title bar of Notepad window, or
clicked in menu File on menu item Exit, or
double clicked on application symbol on left side of title bar of Notepad window, or
clicked once on application symbol on left side of title bar of Notepad window and clicked next on last application context menu item Close.
Then internal command START of cmd.exe is used to start Microsoft Word in a separate process parallel to running command process. For that reason cmd.exe continues the batch file processing immediately after executing START while Microsoft Word is running parallel and exits because there is no more command line.
The application to start must be specified usually with full path if the directory containing the executable is not included in environment variable PATH, enclosed in double quotes if the path contains a space or one of these characters &()[]{}^=;!'+,`~. Please take a look on What is the reason for '...' is not recognized as an internal or external command, operable program or batch file? for details on how Windows command interpreter finds executables and scripts specified on command line or in a batch file without path (and without file extension). So best would be as second line something like:
start "" "%ProgramFiles(x86)%\Microsoft Office\Office14\Winword.exe"
This command line starts 32-bit Microsoft Word 2010 installed in standard installation directory on a computer running 64-bit Windows. The additional empty argument string "" is necessary because command START would interpret otherwise the full qualified name of application to start enclosed in double quotes as title for a new console window. So the command START would start a new command process with the title C:\Program Files (x86)\Microsoft Office\Office14\Winword.exe for the console window without specifying explicitly an empty title with "" as first argument.
Why is using just start Winword.exe working?
The directory containing Winword.exe is not included in environment variable PATH. But as long as Winword.exe is installed at all, this command line nevertheless results in starting Microsoft Word. The reason is correct registration of application Winword.exe in Windows registry during installation. For that reason the command START is capable to find out where Winword.exe is installed and execute it. For details on how this works see answer on Where is “START” searching for executables?
The three lines in batch file can be also optimized to a single line with multiple commands:
#%SystemRoot%\Notepad.exe & start Winword.exe
But this single command line can't be used directly in a command prompt window because of cmd.exe executes in this case Windows Notepad and Microsoft Word parallel.
Command line solutions
The command line solution for usage directly from within a command prompt window is:
start /wait Notepad.exe & start Winword.exe
This starts Windows Notepad in a separate process using command START with explicitly waiting for termination of Notepad.exe because of using additionally the START parameter /wait before one more START is executed to start Microsoft Word. There is no need of "" as empty title string here because of no argument string in this command line is enclosed in double quotes.
But this command line solution has one disadvantage: the command prompt window can't be used further as long as Windows Notepad is running.
So better would be starting from within current command prompt window a new command process with minimized window which first executes Windows Notepad, halts command line execution until Notepad terminates itself, then starts Microsoft Word and exits immediately after starting Winword.exe. This can be done with following command line:
start "Notepad & Winword" /min cmd.exe /C "start /wait Notepad.exe & start Winword.exe"
This command line results in starting cmd.exe as separate process, with a console window being minimized because of option /min of command START, with a console window title Notepad & Winword, which closes itself because of option /C of CMD, after first starting Notepad.exe and waiting for Notepad termination before starting Winword.exe not waiting for termination.
Well, the additional, minimized console window with title Notepad & Winword is in real of no usage for the user. Therefore better would be the command line:
start "" /B cmd.exe /C "start /wait Notepad.exe & start Winword.exe"
The additional command process is started in this case with no window (in background) because of usage of option /B of command START. An empty title is specified here as no console window is shown at all.
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
cmd /?
echo /?
start /?

Difference between calling "start myapp" and "myapp"

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?
taskmgr
C:\Windows\System32\Taskmgr.exe
start taskmgr
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?
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.
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
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.

cmd.exe doesn't terminate when using a .bat file

[Context: I'm trying to create a shortcut to a .bat file with a relative "Start in" path as roughly described here and here.]
cmd.exe supports the /c switch. According to the documentation, this should cause it to "carry out the command and then terminate."
But the switch seems to be ignored when the command is a .bat file.
For example, if you create a shortcut with the following Target (to a normal, non-bat command):
C:\Windows\System32\cmd.exe /c "START /d C:\temp\ notepad.exe test.txt"
Everything works as expected: Notepad opens and the console (shell) disappears. But if you replace the command above with a .bat file instead, like so:
C:\Windows\System32\cmd.exe /c "START /d C:\temp\ C:\test.bat"
(where test.bat contains only "notepad.exe test.txt") Notepad opens as before but the console sticks around like an unwanted friend. Why? And more to the point, How do I make it go away?
UPDATE: I know I can use wscript, as in this solution, but then I lose the option of having a custom icon (I'm stuck with the default .vbs icon).
The start command begins a new process for the batch file. The original cmd.exe then terminates, but leaves the new process, which hangs around because it's waiting for notepad.exe to terminate.
Change your bat file contents to:
start "" notepad.exe test.txt
Then your batch file will not wait for notepad to exit before continuing execution.
Another thing to try:
C:\Windows\System32\cmd.exe /c "START /d C:\temp\ C:\test.bat & exit"
The nuclear option would be to write a small program in the (compiled) language of your choice that launches the .bat file and then exits. Then you can give it a custom icon, and make it do whatever you like.
You might also take a look at Autoit from http://autoitscript.com as an alternative to batch. - the Run() command can do this kind of thing with better predictability. Since it makes an executable you can link this from a shortcut directly. You can also do a whole lot more of course, like run as a different user, insert delays or handle errors, that are hard to do with batch.
You don't need the full kit, just the Aut2EXE folder from the download will do.
BTW, build your exes without UPX compression as that leads to AV false positives.
I'm a little late but here is the answer.
The documentation for start states:
Syntax
START "title" [/D path] [options] "command" [parameters]
If command is an internal cmd command or a batch file then the command
processor is run with the /K switch to cmd.exe. This means that the
window will remain after the command has been run.
If start is used to execute a batch file, the opened cmd instance wont close.
You could also use call instead.
call C:\test.bat

Why can't I start programs in the command line without /d? (Windows 7x64)

I am trying to create a batch script that opens a program. I am doing some testing and I can't figure this out:
If I run CMD.exe and input start /d "C:\wamp" wampmanager.exe the program opens
but
If I run CMD.exe and input start "C:\wamp\wampmanager.exe" I get "the current directory is invalid"
Now when I try to do start runas /profile /user:Administrator "C:\wamp\wampmanager.exe" I get prompted for Administrator's password, but nothing happens when I enter it.
Can someone please tell me how I can run the above command?
Because the start program's syntax expect the window title as its first quoted argument.
(see start /?). You can supply an empty string, however:
start "" "C:\wamp\wampmanager.exe"
or, if you don't need quotes to mask parts of the path, just leave them out altogether:
start C:\wamp\wampmanager.exe
start "some-text"
starts a new command window with "some-text" as the title of the window. To start a program, do not use the quotes around the argument
start program-name

How to start an application without waiting in a batch file?

Is there any way to execute an application without waiting in batch file? I have tried the start command but it just creates a new command window.
I'm making a guess here, but your start invocation probably looks like this:
start "\Foo\Bar\Path with spaces in it\program.exe"
This will open a new console window, using “\Foo\Bar\Path with spaces in it\program.exe” as its title.
If you use start with something that is (or needs to be) surrounded by quotes, you need to put empty quotes as the first argument:
start "" "\Foo\Bar\Path with spaces in it\program.exe"
This is because start interprets the first quoted argument it finds as the window title for a new console window.
I used start /b for this instead of just start and it ran without a window for each command, so there was no waiting.
If your exe takes arguments,
start MyApp.exe -arg1 -arg2
If start can't find what it's looking for, it does what you describe.
Since what you're doing should work, it's very likely you're leaving out some quotes (or putting extras in).
EDIT moved /B parameter/switch to before the command path, as per Nime Cloud's recommendation
I successfully used a combo of #joey's post, with added /B flag, as follows
START "" /B "Path\To\Application.exe"
Partial output from help command: HELP START...
B Start application without creating a new window. The
application has ^C handling ignored. Unless the application
enables ^C processing, ^Break is the only way to interrupt
the application.
This command starts ClamAV in a seperate console window with custom icon of clamd.exe
start "c:\clamav\clamd.exe" "c:\clamav\clamd.exe"
So the generic format would be like:
start "Your new title" "c:\path\your.exe"

Resources