how to open unregistered file in not installed pro

2019-06-01 07:39发布

Firstly, I've seen this.

Now, I would like to open a file which has unregistered extension in the program which is not installed in windows, all via batch.

START "%~dp0\arch\file.nesta" "%~dp0\Virtua.exe"
rem this will open only program

pause

START "" "%~dp0\arch\file.nesta" "%~dp0\Virtua.exe"
rem and this will summon "Open in program" win window

Point is to drop a file into program with one (double) click.
(exe file and bat file ar in same folder while file is in "arch" subfolder)

1条回答
一夜七次
2楼-- · 2019-06-01 08:01

Syntax for command START

Squashman has given already the (nearly) right answer which I explain here in more details.

Running in a command prompt window start /? displays help for this command also described by Microsoft on page about command start with entire command line reference in menu on left side.

After command START there should be specified the "title for command window" in double quotes. This can be also an empty string specified with "" if the application to start is a GUI application and not a command or console application. The title of the GUI window is always defined by the GUI application and not by command processor. So a meaningful title string instead of an empty title string makes sense only for console applications and commands of Windows command processor executed in a new console window.

A title string in double quotes is not necessary if there is no string on entire line enclosed in double quotes because no parameter string contains a space or a character from this list: &()[]{}^=;!'+,`~ This character list is displayed at end of last output help page on running in a command prompt window cmd /?

Then one or more of the optional parameters of START itself must be specified on the line if one of those parameters is required for the task at all.

The next parameter must be the command or application to run as new process. START can be also used to just start a new command process with a new console window and therefore a command or application must not be specified. But START is used in in batch file usually to run an application in a separate process and not for just opening a new command prompt window.

And last are specified the parameters of the command or application to start.

What does this mean in practice?


Command START with one parameter in quotes

START "%~dp0\arch\file.nesta"

Command START creates in this case a new command process with Drive and path of batch file\arch\file.nesta as title for the new console window displayed in title bar of the window. So the single string in double quotes is interpreted by command START always as title string for a new command window.


Command START with two parameters in quotes in wrong order

START "%~dp0\arch\file.nesta" "%~dp0\Virtua.exe"

This results in starting Virtua.exe in directory of batch file with Drive and path of batch file\arch\file.nesta as title for the new console window in case of Virtua.exe is a console application.

But even if Virtua.exe is a GUI application, the string %~dp0\arch\file.nesta is already taken by command START as window title not being displayed anywhere and therefore Virtua.exe is always started with no parameter using this command line.


Command START with two parameters in quotes in right order with missing required title string

START "%~dp0\Virtua.exe" "%~dp0\arch\file.nesta"

This results (most likely) in an error message as Drive and path of batch file\Virtua.exe is interpreted as title and command processor can't find in directory Drive and path of batch file\arch a file with name file.nesta.* with a file extension listed in environment variable PATHEXT.


Command START with two parameters in quotes in right order and with required title string

START "" %~dp0Virtua.exe" "%~dp0arch\file.nesta"

This is the right command to start Virtua.exe in directory of batch file with file.nesta in subfolder arch of batch file folder as parameter for Virtua.exe and given the console window no title if Virtua.exe is a console application.

There is no backslash after %~dp0 as this string is expanded by command processor always to drive and path of batch file ending already with a backslash before command START processes the parameters.

Using %~dp0\ would result in \\ between path of batch file folder and for example Virtua.exe which is not 100% correct. However, Windows automatically cleans up file and folder strings with \\ inside and therefore this small mistake would have no effect on execution.


Summary

  1. On specifying ALWAYS first a title string in double quotes after START makes your batch coding life easier.

  2. Using "" for a GUI application and "Something meaningful" for a command or console application as title string makes it easier for the users of the batch file to identify what the opened console window is for in list of running applications displayed on using Alt+Tab, in Windows task bar depending on the used task bar options (just symbol displayed or symbol with begin of window title) and in Task Manager of Windows.

Note:

There are combinations of not quoted parameters and quoted parameters which do not require a quoted title string. But it is really much easier to specify always a title string instead of finding out when a title string in quotes must be specified and when it is possible to omit it if any parameter is enclosed in quotes.

查看更多
登录 后发表回答