How to add cmd command execution to right click menu on Windows? - windows

I’m trying to add a menu button when I right click a file and the button will let me execute a command. To be more specific, I’m trying to right click a apk file, and the I can execute a “adb install” command of the selected file. I did some search and found out to add a menu item we need to modify the registry. But I’m not sure how to execute a command and moreover, how can I get the current selected file in right click?
Any help will be much appreciated!

Read about Verbs and File Associations on MSDN.
If you don't need it to be the default command, adding it under SystemFileAssociations is a good idea and works on Windows XP and later.
A minimal .reg file might look like this:
REGEDIT4
[HKEY_CURRENT_USER\Software\Classes\SystemFileAssociations\.apk\shell\AdbInstall]
#="ADB Install"
[HKEY_CURRENT_USER\Software\Classes\SystemFileAssociations\.apk\shell\AdbInstall\command]
#="\"C:\\path\\to\\androidsdk\\adb.exe\" install \"%1\""
%1 is replaced with the full path of the file you right-click on.

Related

Using cmder . Windows 10

I downloaded Cmder on my PC but I want that the cmd starts on a folder as then I can navigate because if not the cmd starts in the Cmder folder and I can't go anywhere. Can someone help me, please? Wish you understood me!
Very simple and best way to get CMDER wherever you want is adding it to de Windows Context Menu (right click).
Open a terminal as an Administrator
Navigate to the directory you have placed Cmder
Execute .\cmder.exe /REGISTER ALL
If you get a message "Access Denied" ensure you are executing the command in an Administrator prompt.
In a file explorer window right click in or on a directory to see "Cmder Here" in the context menu.
From: https://github.com/cmderdev/cmder#shortcut-to-open-cmder-in-a-chosen-folder
Tip: put the CMDER files in c:\Program Files\CMDER
If I understood you correctly, you want to change the directory you start from each time you open a new terminal.
To do that:
click Win+Alt+t to open the settings
In the settings group 'Startup' choose 'Tasks'
Choose the console you want to modify (e.g. cmd::Cmder, cmd::Cmder as Admin, etc..)
Click the 'Startup dir...' button
Select the directory you want the console to startup in by default
Enjoy!
You dont give us much to go on but you should have a shortcut with which to start cmder perhaps on your desktop something like this.
If not find your installed copy of cmder.exe then Right Click it then select Send To
and then finally select "Desktop (as shortcut)"
Right click the shortcut and select Properties of that shortcut and then add your prefered starting DIRectory after a /start DIRective
If you want to Autorun other start-up commands see
https://stackoverflow.com/a/68185482/10802527

To open a folder in Terminal

Is there any option to open the program files in Terminal(windows) directly from the folder's location in the drive, without actually typing all the commands to navigate and then executing it.
I guess "open in Terminal" option in present in Ubuntu;
You can achieve this in a number of ways.
Click on File at the top left corner of the current folder location. You will see Open Windows PowerShell option. Click on any option. It will open Power Shell and automatically navigate to the current folder.
Another option, Press Shift and Right Click. It will show Open PowerShell window here option.
If you are looking for Ubuntu-like terminal(bash) then you can install the Git terminal from here. Then, on right-click you will see Git Bash Here option.

How to make the cmd line executable

Here's the situation, every time I need to do the step below after I boot my computer:
Open the cmd(admin)
copy this cmd into cmd:
C:\Windows\system32\netsh int ipv4 set glob defaultcurhoplimit=65
enter
For now, I hope to double click a file that can directly execute the command above without the step above.
Any method?
You can save it to .bat or .cmd file and run it on double-click.
Create a file with any name and extension .bat I.g. setLimit.bat. I assume you know how to create files.
Open file from above step in file editor, i.g. notepad.exe. Copy and paste line C:\Windows\system32\netsh int ipv4 set glob defaultcurhoplimit=65 into the file and press Ctrl+S to safe it. I hope it makes sense otherwise ask.
Double click on the file to execute the command.
If you need to run it under elevated privilege (i.e. admin) right click on file and choose Run as administrator option in menu.
You need a .bat file to execute the command and a shortcut to have it executed as administrator.
Creating the .bat file is trivial: use you favorite text editor (or notepad), type the command, optionnaly add a line PAUSE if you want to see eventual messages and save it to disk with a .bat extension (say c:\...\sethoplimit.bat)
Creating the shortcut is not much harder: right click on desktop, Create new..., Shortcut, and just select the newly created file
The magic comes now: right click on the newly created shortcut and click Properties, in Shortcut tab, click the Advanced button and select Execute as admin.
That's all. Each time you double click on the shortcut, Windows will start a console with elevated priviledges, eventually open the User Account Control confirmation dialog, and execute the batch file as administrator.
Here I showed you how to create the shortcut directly on the Desktop, but the same process can be used for a shortcut anywhere on a disk folder.

How to run a .bat from inside the IDE

What I want to do is very simple, yet can't find the way to do it.
In my projects I have several .bat files (I know, I'm old) the perform some tasks like running SqlMetal, etc.
I just want to right-click the file and select "run" or something so the bat is executed. How do I do it?
Note: I know I can use Tools -> External Tools, but it's not what I'm looking for
If each project has a few batch files associated with it then why not include them in the project and add a new external tool and link it with a custom menu item to run the tool? This will give you a list of batch files in each project and a context menu command to run them. The only downside is that it isn't file type specific (it will let you run any file as a batch file).
Here's how to do it...
Create an external tool called "Run batch file"
Set the Command to: CMD.EXE
Set the Arguments to: /c "$(ItemPath)"
Set the Initial directory to: $(ItemDir)
Check the "use output window" checkbox and then Apply to create the command
Note where the new command appeared in the list of commands. The external commands are numbered from 1 starting below the divider bar. #1 is usually "Create GUID"
Now go to Tools -> Customize and select the commands tab.
Select the Context menu radio button and select "Project and Solution Context menus | Item" from the dropdown.
Now use "Add Command..." to add a new command
In the Categories list select "Tools"
From the commands select the "External Command #" that corresponds to the position of the "Run Batch file" custom command you noted the number of in step 5 above.
Move it to the correct position in the list add keyboard shortcuts etc.
Close the dialog.
Now right click on the batch file and you should see a "Run batch file" menu item. This will execute the batch file and show its output in the VS Output window.
Right click the batch file in the Solution Explorer
Select “Open With…” from the context menu
Click “Add…”
In the “Program name” textbox, enter powershell.exe
In the “Friendly name” textbox enter “PowerShell”
Select “Set As Default”
Click OK
via
Check out the Open Command Line Visual Studio extension.
As per the description, it features:
Opening of a command line at the root of the project.
Support for all consoles such as CMD, PowerShell, Bash etc.
Syntax highlighting, Intellisense and execution of .cmd and .bat files.
For files in your solution, a context-menu button shows up.
Alternatively, the keyboard shortcut Shift+Alt+5 can be used when editing a batch file. This makes it really easy and fast to execute any batch file - even ones that are not part of your project.
Right-click a file in the Solution Explorer window, Open With, click the Add button to add your .bat files. Use %1 in your .bat to get the path to the selected file.
Couldn't get any of the above to quite work, but this did (VS 2019/2022):
Right click a .bat file in Solution Explorer and Open With...
Add...
Program: CMD.exe
Arguments: /c %1
Friendly name: Command
OK and Set as Default for double clicking of batch files to run from Solution Explorer as the default (or right click Open With... and select Command if you don't want it the default).
Merely a suggestion: This is a scenario which can be done with the VsCommandBuddy extension. The following configuration is an example:
{
"cmdname": "mk",
"title": "Run MK.BAT",
"description": "Run the MK bat file.",
"cwd": "$(SolutionDir)",
"filename": "cmd.exe",
"arguments": "/C mk.bat",
"async": false
}
You can assign shortkeys as well, so you can invoke your batch files with shortcut keys. Output comes in your output pane.

BAT file to open CMD in current directory

I have many scripts which I interact with from the command line. Everytime I need to use them, I have to open a command line window and copy+paste and CD to the path to the directory they are in. This is tedious (they are in a rather deep file system, so typing out the full path is a pain, copy+paste is better but not much). I tried to create a .BAT file that I could double-click on that would open a new command-line window in the folder the .bat file exists in but it does not work. It opens a new window, but the working directory is not the directory that .bat file is in. Here's what I've got after much googling (My cmd skills ain't so great):
cd %CD%
cmd.exe
I know from when I used Linux that Konqueror had a "Command-line window here" feature, and that's the effect I'm trying to get on Windows.
you probably want to do this:
cd /d %~dp0
cmd.exe
this will set your current directory to the directory you have the batch file in
Create a file named open_dos_here.cmd with the following lines:
%~d1
cd "%~p1"
call cmd
Put this file at any folder.
Then, go to your Send To folder (Win+E; Alt+D;shell:sendto;Enter).
Create a shortcut to point to this open_dos_here.cmd
Then, in any folder, select any file or sub-folder. Right-click and select "Send To" and then select open_dos_here.cmd to open the DOS in that folder.
You can just enter cmd into the address bar in Explorer and it starts up in that path. Likewise for PowerShell.
There's a simpler way -
start /d "folder path"
As a more general solution you might want to check out the Microsoft Power Toy for XP that adds the "Open Command Window Here" option when you right-click: http://www.microsoft.com/windowsxp/downloads/powertoys/xppowertoys.mspx
In Vista and Windows 7, you'll get that option if you hold down shift and right-click (this is built in).
I'm thinking that if you are creating a batch script that relies on the Current Directory being set to the folder that contains the batch file, that you are setting yourself up for trouble when you try to execute the batch file using a fully qualified path as you would from a scheduler.
Better to add this line to your batch file too:
REM Change Current Directory to the location of this batch file
CD /D %~dp0
unless you are fully qualifying all of your paths.
Another solution is to use a shortcut file to cmd.exe instead of a batch file.
Edit the shortcut's start in property to %~dp0.
You achieve the same thing, except it has the Cmd icon (and you can change this).
Some people don't like clicking on batch files without knowing what's in them, and some corporate network drives have a ban on .bat files...
The simplest command to do this:
start
You can always run this in command line to open new command line window in the same location. Or you can place it in your .bat file.
Most simple way in explorer is to Shift + right mouse click on the folder or on an empty space in the folder and click on Open command prompt here.
CMD will then start in that folder
I must say, I'm not sure if it works for Windows Vista and below, but it surely works for Windows 7, 8, 8.1 and 10.
Referring to answer of #Chris,
We can also go to parent directory of batch file and run commands using following
cd /d %~dp0..
<OTHER_BATCH_COMMANDS>
cmd.exe
To understand working of command cd /d %~dp0.. please refer below link
What does it mean by command cd /d %~dp0 in Windows
You could add a context menu entry through the registry:
Navigate in your Registry to
HKEY_LOCAL_MACHINE/Software/Classes/Folder/Shell
and create a key called "Command Prompt" without the quotes.
Set the default string to whatever text you want to appear in the right-click menu.
Create a new key within your newly created command prompt named "command," and set the default string to
cmd.exe /k pushd %1
You may need to add %SystemRoot%\system32\ before the cmd.exe if the executable can't be found.
The changes should take place immediately. Right click a folder and your new menu item should appear.
Also see http://www.petri.co.il/add_command_prompt_here_shortcut_to_windows_explorer.htm
When you are in the desired folder , just type CMD in your address bar
A bit late to the game but if I'm understanding your needs correctly this will help people with the same issue.
Two solutions with the same first step:
First navigate to the location you keep your scripts in and copy the filepath to that directory.
First Solution:
Click "Start"
Right-click "Computer" (or "My Computer)
Click "Properties"
On the left, click "Advanced System Settings"
Click "Environment Variables"
In the "System Variables" Box, scroll down and select "PATH"
Click "Edit"
In the "Variable Value" field, scroll all the way to the right
If there isn't a semi-colon (;) there yet, add it.
Paste in the filepath you copied earlier.
End with a semi-colon.
Click "OK"
Click "OK" again
Click "OK" one last time
You can now use any of your scripts as if you were already that folder.
Second Solution: (can easily be paired with the first for extra usefulness)
On your desktop create a batch file with the following content.
#echo off
cmd /k cd "C:\your\file\path"
This will open a command window like what you tried to do.
For tons of info on windows commands check here: http://ss64.com/nt/
Create a new file startCmdLine.bat in your directory and put this line in it
call cmd
That is it. Now double click on the .bat file. It works for me.
You can replace call with start, it will also work.
this code works for me
name it cmd.bat
#echo off
title This is Only A Test
echo.
:Loop
set /p the="%cd%"
%the%
echo.
goto loop
you can try:
shift + right click
then, click on Open command prompt here
Inside given folder click on the top Adddress Bar and type cmd and click enter
It will open command prompt with current folder address.
You can simply create a bat file in any convenient place and drop any file from the desired directory onto it.
Haha. Code for this:
cmd

Resources