Opening a file using specific application from Windows Command prompt - terminal

In Linux you type the command( open fileName -a "application to open the file with") what is equivalence to this in Windows Command Prompt.

if application in your path environment variable use this :
application_name "C:\Users\path_of_file"
if not use this :
"C:\Program Files\path_application" "C:\Users\path_of_file"

Related

How to open the Windows Startup folder in file explorer via bash?

Startup folder path: %APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup, I've tried:
echo "$APPDATA\Microsoft\Windows\Start Menu\Programs\Startup"
start "$APPDATA\Microsoft\Windows\Start Menu\Programs\Startup"
Although the echoed path is correct, the start command just opens a CMD window, does anyone know how to open the Startup folder in file explorer via bash?
P.S. I'm using Git Bash.
The following command does the job:
start '' "$APPDATA/Microsoft/Windows/Start Menu/Programs/Startup"
Reference: Can I use the "start" command with spaces in the path?

Open file with spaces in filename using Ubuntu for Windows (WSL) - cmd.exe

I am using Windows 10 Fall Creator's Update (version 1703) with Ubuntu app installed (WSL), which can natively launch Windows programs using cmd.exe /C start "".
My goal is to open files in /mnt/d using the default windows application for a file.
It works for me most of the times except when I want to open file names with spaces in them. In those cases, it just opens cmd.exe window and prompt in the equivalent windows directory path where the file belongs. It does not open the file in default application.
For example, if I have files courses.py and a file name with spaces.py in /mnt/d/files
cmd.exe /C start courses.py - opens courses.py in VS Code.
cmd.exe /C start a\ file\ name\ with\ spaces.py - opens cmd.exe with prompt at D:\files
Am I providing the file name in WSL incorrectly?
#Compo provided the solution in the comments:
cmd.exe /C start "" "a\ file\ name\ with\ spaces.py"
Since I use wsl-terminal, I got past this issue by using this neat built-in command:
cmdtool wstartex <file|url>

Trying to open programs with bat file but always comes back invalid

I am a streamer and I need a few programs to stream. It's annoying to open all of them so I tried putting them in a batch file. I looked up the process and followed it,but every time I run the batch file it comes back invalid.
This is what my batch file looks like:
#echo off
cd C:\Program Files "(x86)\obs-studio\bin\64bit"
start obs64.exe
#echo off
cd "C:\Program Files\HexChat"
start hexchat.exe
#echo off
cd "C:\Program Files (x86)\Nightbot"
start nightbot.exe
exit
Cmd gives me an error saying it cannot find the file. When I put this into cmd by itself it opens the program.
Also is there a way to add applications from chrome to the file?
Open a command prompt window and run from within this window start /? which outputs the help for this command and explaining all options.
Following batch file most likely works:
#echo off
start "" "%ProgramFiles(x86)%\obs-studio\bin\64bit\obs64.exe"
start "" "%ProgramFiles%\HexChat\hexchat.exe"
start "" "%ProgramFiles(x86)%\Nightbot\nightbot.exe"
This batch file starts the three applications with current directory on execution of the batch file being also the current directory for the 3 started applications.
But the following batch file should be used if it is really necessary that each application is started with the application's directory as current directory:
#echo off
start "" /D"%ProgramFiles(x86)%\obs-studio\bin\64bit" obs64.exe
start "" /D"%ProgramFiles%\HexChat" hexchat.exe
start "" /D"%ProgramFiles(x86)%\Nightbot" nightbot.exe
With parameter /D and path of application's folder the Start In directory is set first like when using command CD. So for example hexchat.exe is started with current directory being C:\Program Files\HexChat for this application.
The two double quotes after command START are necessary as this command interprets first double quoted string as title for the process. By using "" an empty title string is explicitly specified resulting in rest of command line being correct interpreted as expected. I suppose those three applications are all GUI applications and not console applications and therefore a real title string being useful on running a console application in an new command process for the console window is not really necessary.
%ProgramFiles% references the predefined environment variable ProgramFiles containing path to standard program files folder for 64-bit applications on 64-bit Windows when batch file is started with 64-bit cmd.exe as default on 64-bit Windows and is replaced by Windows command interpreter before execution of the command line on your Windows computer by C:\Program Files.
%ProgramFiles(x86)% references the predefined environment variable ProgramFiles(x86) containing always path to standard program files folder for 32-bit applications on 64-bit Windows and is replaced by Windows command interpreter before execution of the command line on your Windows computer by C:\Program Files (x86).
It is of course also possible to use the real paths in your computer instead of the environment variable references if this batch file is never shared with other people.
Extra hint:
Run in a command prompt window the command you want to use with /? as parameter to get displayed the help for this command. Other sources for help on commands and predefined environment variables displayed all on running in a command prompt window set are:
SS64.com - A-Z index of the Windows CMD command line
Microsoft's command-line reference
Windows Environment Variables and WOW64 Implementation Details

open files by command prompt which are in system PATH variable

My system PATH variable contains "C:\myfiles" and I have a file "C:\myfiles\abc.txt".
Now I want to open it by notepad via command prompt using just "notepad abc.txt"
I expect it to open "C:\myfiles\abc.txt" (just like Bash), but it opens a file from my home directory.
How to make command prompt to search for files in PATH variables first?
in a computer property>>advanced system setting >> system property >> envirmental veriables>> then select system variables path>> click on edit system variables path >> add new<C:\myfiles> or edit append in last <;C:\myfiles>
now just type in run box or cmd prompt>> abc.txt

Unable to open application by specifying it's location under App Paths

I have created a key(for example myapp.exe) under "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths" with below values in registry.
(Default) --> C:\Program Files\folder1\folder2\myapp.exe
Path --> C:\Program Files\folder1\folder2\;
Then I opened a command prompt and tried to open my application. But I am getting an error like "'myap.exe' is not recognized as an internal or external command,operable program or batch file."
If I add the directory where my application resides to Path environment variable, then I am able to run the application successfully from command prompt.
please let me know where I went wrong.
This is another way to start an application from the command prompt.
Create a batch file similar to the following and call it FR.BAT which is short for foxit reader in this example, and store the FR.BAT file in c:\windows or another directory on the PATH.
When you open a CMD prompt and type fr then it will launch this batch file and start the application.
#echo off
start "" "c:\Program Files\Foxit Software\Foxit Reader\Foxit Reader.exe"
Just be careful not to use a name which is the same as an existing Windows command.

Resources