Create new "execute" function/program in Windows (instead of command prompt) - windows

I am using a small program called Youtube-DL to download videos but everytime I have to open the command prompt, get to the right folder and then execute, say, youtube-dl https://www.youtube.com/watch?v=uFk0mgljtns.
What do I need to set up so that I can do the same thing directly from the "execute" tool (the one you access with the shortcut Windows+R)? Ideally all I would need to do would be Windows+R, type yt-dl https://www.youtube.com/watch?v=uFk0mgljtns.

Add the youtube-dl executable to your %path%: Use setx /M PATH "%PATH%;C:\folder_with_youtubedl" with an admin cmd.

Related

Cygwin: launch bat with parameter, in new window, with explorer environment

I need to run some .bat files from Cygwin. Until now, these bat files didn't required any param, so I used the following method:
chmod +x $strBatFilename
cygstart "$WINDIR/explorer.exe" "$strBatFilename"
These commands implement 2 features that I need:
The .bat file is opened in a new window
The environment of the new window is the explorer's one, not the one of Cygwin
The problem that I have is that now I need to also pass a parameter to the bat file.
I don't know of a method to call explorer.exe with a file (my bat) as parameter and having some extra option to pass another parameter to the bat (sounds like passing a parameter to a parameter of explorer.exe).
I have searched and found that I can start a cmd.exe. I tried starting it directly or starting it using cygstart:
cygstart $WINDIR/system32/cmd.exe /c start "$strBatFilename $strBatParam"
I have managed to make it start in a new window and launch the .bat with a parameter, but the environment is not the explorer's one.
I don't know the exact differences between the two environments. What makes me say they are different is that when for example the bat contains a repo sync command, if it's open with explorer it runs the repo sync command smoothly, while if the bat is called from cmd.exe, the repo sync command will ask for my user name and email.
So, my question is: are you aware of any command that will start from Cygwin a .bat file
passing a parameter to it
opening it in a new window
having the new window inherit the explorer's environment ?
Thank you

How to set ps as shortcut to open powershell

The question says it all. I want to learn and use powershell as my go to terminal in windows and I want powershell to open if I type Win+R followed by ps. Much like how cmd is used to open command prompt.
You can create a symbolic link (similar to a shortcut) to Powershell with any name you want.
This will create one called ps.exe in the powershell folder, this folder is already listed in PATH so will enable you to run ps from the RUN box like you want.
mklink %SystemRoot%\system32\WindowsPowerShell\v1.0\ps.exe %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
Be sure to run the command in an elevated command prompt.
The "default" command for opening PowerShell is powershell. If you want to make it ps, your best bet is to create a batch file named ps.bat containing the single line
#powershell %*
and place it in one of the directories named in your system PATH variable.

Start Command in CMD Window

I use below command in CMD window:
start notepad.exe
Is start a short-cut for an executable in Windows like:
C:\Windows\System32\start.exe
or is it a parameter to be passed to cmd.exe?
When I use
wcsript test.vbs
wcsript refers to
C:\Windows\System32\wcsript .exe
So I want to ask does same apply for start command?
Some commands available in CMD are built directly into CMD.EXE. I believe start, like dir, is one of those commands. You won't find a separate program called dir.exe or start.exe.
You do not need to use start, simply the location of your script with the filename+extension works.
The reason you can start notepad is because it is inside the Windows folder where CMD also is.
If it's on your desktop use: C:\Users\%Username%\Desktop\test.vbs
If you have multiple files you can make a script using:
cd C:\Users\%Username%\Desktop\
test1.vbs
test2.vbs

Using Batch File to Open Another Cmd Prompt and Run Cmd in that Cmd Prompt

I have another bat file that I'm running, and once in the command prompt that bat file creates, I want to run another command in that window.
Here's what I have so far:
call C:\Batch\MyBatFile.bat (this creates the new command prompt that I want to use)
C:\Program\MyProgram.exe
However, the second line is being run in the original window, instead of the new command prompt. I tried using start C:\Program\MyProgram.exe, but that just ran in a 3rd new window instead.
If it's relevant, the first line is just setting a few environment variables that I need access to and MyProgram is a visual studio 2010 project. Technically, I might be able to modify that bat to run the command, but I'd rather avoid that solution as that bat file isn't owned by me (and thus whenever it's updated I'd have to update mine as well).
Thanks in advance.
You could try to inject your program.exe into cmd created by batfile.bat by redirecting it's input stream and then sending it a command, eg. echo C:\Program\MyProgram.exe | C:\Batch\MyBatFile.bat. This assumes that batch really just sets bunch of variables and does not use commands which reset/consume input stream.
Please note that if redirected/piped this way new command window will not stay open It will maybe :-) just execute your command and then close/exit.
Create a CMD script to run both of the commands that you have shown in the question. Maybe call it RunMyProgram.cmd. The contents are just the two lines that you have:
REM Source the environment variables.
REM Any new command prompt window that is opened can be ignored
CALL C:\Batch\MyBatFile.bat
C:\Program\MyProgram.exe
If what you have stated in the comments to your question is accurate regarding MyBatFile.bat setting up the environment variables and then starting a new window, then you should be able to make use of those environment variables after MyBatFile.bat exits.
If running RunMyProgram.cmd from a command prompt still has MyProgram.exe giving the error when the environment variable is not set, or if MyProgram.exe doesn't even start to run until you close the new window that popped up, then we need to see the exact commands that MyBatFile.bat is executing.

Windows CMD: How to create symbolic link to executable file?

My goal is to add a few executables to my PATH (for example, chrome), so that I can call
> chrome
from the command prompt and it will launch Chrome.
I know I could add Chrome's containing directory to my path (set PATH=%PATH%<chrome_path_here>;), but since I have a few executables I want to add, I'd rather make a new bin directory that contains symbolic links to the actual executables and just add that single directory to my PATH.
The Chrome executable is located at
C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
So I tried
> mklink chrome.exe "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
That successfully creates a symbolic link for the files (says so in output, and upon examining with > dir). I know my PATH is set up correctly, b/c when I run > where chrome it finds my new symbolic link.
However, when I try to execute chrome with my new link, nothing happens. A new empty window should appear, but nothing happens. No error message in the command prompt or anything.
What am I doing wrong? Am I misunderstanding symlinks in Windows? This is the approach I use in Linux all the time, but I'm new to Windows Cmd.
Thanks!
Most programs will not run from places other than they install location - which is exactly what happens when you try to run it from symlink.
It would be much easier to create CMD/BAT files in that folder with matching names which will launch programs from locations you want:
REM chrome.cmd
start /b cmd /c "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" %*
With Windows 7 I confirm that symlinks do not work, are simply ignored as reported in the original question.
As Harry states in his comment, shortcuts do work, and to me are simpler and easier than writing a separate script for each new command I want to enable under CMD.
He states that you need to add .lnk to your PATHEXT variable in order to do this. I affirm that this does work, and with .lnk added to PATHEXT I can simply enter the name portion of the shortcut to run the command. For example if my shortcut is named "sublime.lnk" and PATHEXT includes .lnk, I can execute the link with the simple command "sublime". Nice!
As an alternative I found that PATHEXT need not be modified if I simply type in the full name of the shortcut, including the .lnk, at my CMD prompt. E.g., I created a shortcut named "sublime.lnk" under %HOMEPATH%/bin, pointing to "C:\Program Files\Sublime Text 2\sublime_text.exe".
Now by placing %HOMEPATH%\bin in my %PATH% I can run sublime via the command "sublime.lnk".
Either of the above are the best way I know of giving access to various commands from around Windows' filesystem from a CMD prompt. I'm not a Windows expert though, and welcome a better or more standardized solution to this problem.
P.S.: I just found out the hard way that you need to ensure the "Start in:" property of any shortcut you use in this fashion is blanked out, or your program will not start in the directory you invoke the shortcut from.
P.P.S.: On a related note, I discovered how to run Windows Explorer (or its replacement) on the directory your CMD session is logged in to: start ..

Resources