Right-click "Open" with arguments - windows

I would like to add an entry to the Windows right-click menu that only appears when I right click on a .exe or .msi file. If the entry is selected, the exe file will be executed (like Open) but with a fixed text string as its argument.
I guess this should be possible with a registry key - any ideas how to do this?

For an .exe file, you can do the following in the registry:
Under HKEY_Classes_Root, find key .exe
Read the (Default) value (this is usually exefile)
Under HKEY_Classes_Root, find key exefile (or whatever you found in step 2)
Under exefile\shell create a new key, with a name matching what you want to see in the context menu (say, "Open With My App")
Under your new key, create a new key called command
Set the (Default) value of this key to whatever commandline you want to execute. The name of the file you clicked on can be entered using the token %1. So, for example, you could set the value to notepad.exe %1 to edit the executable in Notepad.
A similar pattern will work for other file types.

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\.exe\shell\Copy Address\command]
#="C:\\Windows\\CopyAddress.exe %1 "
[HKEY_CLASSES_ROOT\.msi\shell\Copy Address\command]
#="C:\\Windows\\CopyAddress.exe %1 "
Change path and menu name(CopyAddress) as per your choice.

Related

Start Windows Command Prompt in Certain Directory

I am usually working within the same directory (or subfolders of it) and it has quite a long path so it would be really convenient if my command prompt automatically started in that directory (instead of C:\Users\username). How can I change the starting folder to the one I want?
There are two main ways to do it:
Create a shortcut that opens CMD in the directory you want (recommended).
Create a Command Prompt shortcut
Access the properties of the shortcut and set the path where you want it to open in the "Start in" field
Change the path that the command prompt uses by default
Open regedit
Go to "Computer\HKEY_CURRENT_USER\Software\Microsoft\Command Processor"
Create a new "String Value" with the name "Autorun" and with the value "cd /d C:\EXAMPLEDIR"

Can a Windows batch file determine its "invoked" filename when invoked with shortcut?

Can a Windows batch file determine its invoked filename when invoked through a shortcut?
For example, I create real.bat, and create its shortcut named phony.bat (.lnk?)
And invoke phony by double-click on it.
Can this batch file detect the name phony.bat instead of real.bat?
Of course I can just copy it to another name, but when I edit one of them, I have to manually sync the content to all files.
The question is related to Can a Windows batch file determine its own file name?, but different.
As in your you mentioned that you've created the shortcut I assume you can create the with any properties you want.
So right click on your lnk file and change the the target line to:
C:\Windows\System32\cmd.exe /c "set "lnk_call=1"&"C:\PATH\TO\your.bat" "
This will change the icon of the link so to set back to batch file cog click on change icon and find the bat file icon in :
%SystemRoot%\System32\SHELL32.dll
Finally in your bat put this line:
if defined lnk_call echo triggered from lnk file
the lnk_call now can be used to determine if your file is called from double clicking on a .lnk file. I don't think it is possible to detect this from a shortcut that anyone else created.
Oh yeah, I found hardlink useful in this case:
mklink /h <link-name> <source-file>
I can create many hardlinks with different name, and they all points to the same file, so I can freely edit any one of them without manually sync their content.

How to set different default programs in windows explorer and command line

I have some ruby scripts and i want to have 2 different default programs for a same file, one program if i double click it in windows explorer just to edit the code (for example in Sublime Text), but when i run it from command line i want the script to be executed. I am using windows 10.
So far, i have set default program for windows explorer sublime text, so the script opens just fine.
In command line i have set
E:\projects\Ruby>assoc .rb
.rb=Ruby.File
and
E:\projects\Ruby>ftype Ruby.File
Ruby.File=C:\bin\ruby200\bin\ruby.exe "%1" %*
Also i have set .RB en the PATHEXT Environment Variables so i just type the name of the script. But the problem is, when i do that, it launches Sublime Text instead of running the script.
If i change default program from windows explorer, it runs just of from command line, but of course it doesn't open sublime text if i double click it.
Is it possible to have 2 different default programs then? One form command line, and another form windows explorer when i double click some script?
It's not easy to do with GUI but it can be done through command line. First of all you have to make your association dynamic. To do it you have to use REG_EXPAND_SZ value type for registry key containing .rb file association. REG_EXPAND_SZ won't be used literally but expanded (=environment variables replaced with their actual values). You can create association with assoc but then you have to use reg add to change it because default type is REG_SZ. Program path must be something like this:
%RUBY_PROGRAM% "%1" %*
Where %RUBY_PROGRAM% is the name of - so far - not existing environment variable. Now you can give a default value to that variable:
setx RUBY_PROGRAM c:\windows\notepad.exe
Now close your command prompt and go to change its properties (from GUI). As alternative you may create a new shortcut for your modified command prompt. Command to execute has to be this:
%comspec% /k ""c:\setup_ruby.bat""
/k lets you execute given batch file at startup, in that batch you just need to set a different value for %RUBY_PROGRAM% environment variable:
SET RUBY_PROGRAM=C:\bin\ruby200\bin\ruby.exe
Now each time you run that special shortcut you will directly execute your Ruby programs. If you don't want to create a special shortcut and you want to apply this rule to every command prompt (regardless where it has been open) then you can add an entry to HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun registry key.
Note that you may just put ftype in startup script (also providing a quit batch) but that will affect all applications until you close command line prompt (even if you double click file from Windows Explorer).

Windows shell add item to context menu when click on blank part of folder

Sorry if this has been asked before, I've been looking around and it's hard to find what I want.
I know how to add a context menu item to a folder like so:
[HKEY_CLASSES_ROOT\Folder\shell\console2]
#="Open Console2 Here"
[HKEY_CLASSES_ROOT\Folder\shell\console2\command]
#="C:\\Program Files\\Console\\console.exe -d \"\"%1\"\""
but, that only works for right clicking on a folder. I want it so that you can be inside the folder, and click a blank part of that folder and get the context menu item as well. I also tried HKEY_CLASSES_ROOT\Directory\shell as well, but it does the same.
I figured out the answer. The folder is actually Directory\Background, you have to add the empty string value of NoWorkingDirectory into it, and the %1 in the command becomes a %V
[HKEY_CLASSES_ROOT\Directory\Background\shell\console2]
#="Open Console2 Here"
"NoWorkingDirectory"=""
[HKEY_CLASSES_ROOT\Directory\Background\shell\console2\command]
#="C:\\Program Files\\Console\\console.exe -d \"\"%V\"\""
Source:
saviert's comment at http://www.howtogeek.com/howto/windows-vista/make-command-prompt-here-always-display-for-folders-in-windows-vista#comment-57856
Console2 rocks. I added an 'Cmd here (Console2)' item to my explorer context menu.
Save the text below in a file named open-console2.reg then open it to import it to the Windows registry.
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\Background\shell\console2]
#="Cmd here (Console2)"
"NoWorkingDirectory"=""
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\Background\shell\console2\command]
#="\"C:\\Program Files (x86)\\Console2\\Console.exe\" -d \"%V\"\\"
Bonus 'bash here' item (assumes you have a Console2 tab named 'bash').
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\Background\shell\console2_bash]
#="Bash here (Console2)"
"NoWorkingDirectory"=""
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\Background\shell\console2_bash\command]
#="\"C:\\Program Files (x86)\\Console2\\Console.exe\" -t Bash -d \"%V\"\\"
I think the relevant part of the TortoiseSVN installer is here. Perhaps you can figure out all the necessary registry keys from that.
None of the above worked for me.
But this does (tested on Windows 7 Pro x64):
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Folder\shell\Open console here\command]
#="u:\\users\\dave\\data\\bin\\Console2\\Console.exe cmd -r \"/k pushd %L\""
Replace the path with the path to your copy of console.exe (of course).
#Ben Voigt mentioned TortoiseSVN, you can also see WinMerge shell extension source code, or at last: create your own extension from scratch; I wanted to do something like this for XP but I have lots of other stuff to do now.
As a workaround, you can just open a folder in XP, and then select View->Explorer Bar->Folders, to have folder tree on left, and then you're able to right-click the folder (active folder gets hightlighted automatically).
Here it is if you prefer MinGW.
#!/bin/sh
reg add 'HKCR\Directory\Background\shell\sh' -d 'Open Bash window here'
reg add 'HKCR\Directory\Background\shell\sh\command' \
-d 'C:\MinGW\msys\1.0\bin\sh.exe -l'
printf 'cd -' >> ~/.profile
superuser.com/a/387273
According to my personal experience of Windows XP (SP3), you can open Console2 inside the current directory with a context menu entry using the following .reg file:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Folder\shell\console2]
#="Console2 Here"
[HKEY_CLASSES_ROOT\Folder\shell\console2\command]
#="C:\Program Files\Console\console.exe -d \"%1\""
If you look at the key value inside regedit.exe , you should see:
C:\Program Files\Console\console.exe -d "%1"
instead of:
C:\Program Files\Console\console.exe -d ""%1""
The latter would open Console2 in its default start directory.
This can be achieved in XP as well.
First open the program Run with the Windows key + R,
and type Regedit in the textbox.
Press Enter.
In the Registry open the Key : HKEY_CLASSES_ROOT
and then : *
You will now see a key called : shell
Rightclick on shell and point to New.
Click in de menu on Key.
Now type a name of your choice which you want to appear in the Rightclick menu.
Rightclick on the name you chose, again point to New and click Key.
Now type : command
Click on command and in the right pane of the Registry doubleclick on (Default).
In the textbox Value Data, type the path to an application you want to open via the chosen name in the rightclick menu.
For example : "C:\Program Files\CCleaner\CCleaner.exe"
Then type after the path : %1,
and leave a space between the end of the path and %1
It should look like this :
"C:\Program Files\CCleaner\CCleaner.exe" %1
This way, it's possible to open any kind of application you want.
There's only one drawback,
you have to rightclick another file to see the chosen name with which you can open the application.
When you rightclick a folder this will not work.

Windows Shell Context Menu option

I need to create an option for all files that would run a batch file located in Windows directory or any other directory.
The batch file will basically delete the files and will also delete it from another server.
I have the batch file working just need the context menu option.
You have to create the following registry entries:
HKLM\Software\Classes\*\shell\yourappname
HKLM\Software\Classes\*\shell\yourappname\command
the first registry entry is a key, the second a string value. Set the value of the command entry to the path of your batch file, e.g. "c:\batch.bat %1"
The '%1' will get replaced by the path the context menu was shown for.
The '*' entry is for all files. If you want your menu to show up for folders/drives/whatever, you have to also add the same registry keys/values for those too, e.g.,
HKLM\Software\Classes\Folder\shell\yourappname
HKLM\Software\Classes\Folder\shell\yourappname\command
HKLM\Software\Classes\Directory\shell\yourappname
HKLM\Software\Classes\Directory\shell\yourappname\command
HKLM\Software\Classes\Drive\shell\yourappname
HKLM\Software\Classes\Drive\shell\yourappname\command

Resources