How to change the path for "run command" "notepad"? - windows

Where is in the registry the path executed when I run the "notepad" command in windows "Start->run command" interface? I want to change it for notepad++ (it is required so, although could look not really good)

If you are like me you use windows run command all the time. I hate using the mouse to point and click a shortcut on the start menu. WIN-R are probably the two most over used keys on my keyboard. After thinking about if awhile I hunted down how the run command works. It turns out that it makes a call to ShellExecute, which I guess is not too surprising. The next thing I wanted to find out was exactly how the commands are resolved. The following is an ordered list of how they are resolved ([1]):
The current working directory
The Windows directory (no subdirectories are searched)
The Windows\System32 directory
Directories listed in the PATH environment variable
The App Paths registry key
Naturally the next thing I wanted to do was customize existing commands or add new commands so I do not have to type as much (standard lazy approach). After examining my options which were to put the executable in one of those paths (since it only locates executables and not shortcuts), modify the path environment variable or add a key to App Paths. The App Paths option seems to be the easiest and most flexible to me. Here is a layout of what you need to do to add an App Paths entry ([1]):
HKEY_LOCAL_MACHINE-->
SOFTWARE-->
Microsoft-->
Windows-->
CurrentVersion==>
App Paths-->
file.exe-->
(Default) = The fully-qualified path and file name
Path = A semicolon-separated list of directories
DropTarget = {CLSID}
Disclaimer: Modifying the registry can cause serious problems that may require you to reinstall your operating system. I cannot guarantee that problems resulting from modifications to the registry can be solved. Use the information provided at your own risk.
The minimum needed to add a new entry is to add the key file.exe where file is the string you want to type into the run command and to add the Default entry which is the fully-qualified path to the file you want to execute. Note that even it the file you are going to reference isn't an exe file you still need to put the .exe on the key. Here is a sample registry file that I created to add a shorter keyword for Internet Explorer:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App
Paths\ie.exe] #="C:\Program Files\Internet Explorer\iexplore.exe"
After entering that entry into the registry I can simply type “ie” at
the run command to open internet explorer.
Here is a list of some common commands I use at the run command:
cmd – Command prompt winword – Microsoft Word excel – Microsoft Excel
outlook – Microsoft Outlook iexplore – Internet Explorer firefox –
Mozilla Firefox notepad – Notepad compmgmt.msc – Computer Management
Console control appwiz.cpl – Add/Remove programs dialog mstsc –
Microsoft Terminal Service Client regedit – Registry Editor
…
If there is some program that I find myself using all the time I figure out what the run command is for it and if there is not a short easy one I add one to my App Paths as described above. Does anyone else have some other common run commands they use?

Related

How do I set "default App" for a file extension to an ".exe" on Windows 10 after April 2018 update

I have spent a very long time researching this. Most of the solutions were posted PRIOR to April 2018, and involved working your way through the "settings" to get to "Choose default Apps by file type".
Choose default Apps by file type
In previous attempts to assign an app to ".rex" I managed to assign it to Notepad. (At that time, I could not find any way to find an ".exe" on my C: drive.)
So as you can see, if you click on Notepad next to the .rex extension, the only option is to go to the "App store".
And as expected, if you click on App store, nothing is found...
App store - no app's found.
So from what I've read in multiple forums, PRIOR to April 2018, Windows 10 still had a way to "browse your hard drive" to find an ".exe". (Just like in older Windows versions.) After some update in April 2018, that capability no longer exists.
In the POST April 2018, has anyone found a way to assign a file extension to an ".exe" on the hard drive???
I think this question would be more suitable for SuperUser (well, unless you want to do it via a program :) ).
Anyway, here's a way of doing things from console (Cmd). I've tried it 1 or 2 years ago, I just tried it now, so it works regardless of Win (10) version.
Start the process from scratch:
Open a Command Prompt window. Create a new file that the OS doesn't know anything about. I chose the extension .zzz:
e:\Work\Dev\StackOverflow\q052008516>ver
Microsoft Windows [Version 10.0.17134.228]
e:\Work\Dev\StackOverflow\q052008516>dir /b
e:\Work\Dev\StackOverflow\q052008516>:: Create a dummy .zzz file
e:\Work\Dev\StackOverflow\q052008516>echo Some dummy text>file.zzz
e:\Work\Dev\StackOverflow\q052008516>dir /b
file.zzz
Try opening the file (DblClick) from a file browser (it's not relevant, but I use Total Commander), or by typing its name in Cmd. That will yield the dreaded dialog:
Create a new file type and associate our extension with it. [MS.Learn]: assoc utility is used to do the job. First, check if such association doesn't already exist:
e:\Work\Dev\StackOverflow\q052008516>:: No output means no association
e:\Work\Dev\StackOverflow\q052008516>assoc | findstr ".zzz"
e:\Work\Dev\StackOverflow\q052008516>:: Same command for a different extension
e:\Work\Dev\StackOverflow\q052008516>assoc | findstr ".txt"
.dic=txtfile
.exc=txtfile
.log=txtfile
.scp=txtfile
.txt=txtfile
.wtx=txtfile
e:\Work\Dev\StackOverflow\q052008516>:: Create a new FileType (ZZZFile) and associate our extension with it
e:\Work\Dev\StackOverflow\q052008516>assoc .zzz=ZZZFile
.zzz=ZZZFile
e:\Work\Dev\StackOverflow\q052008516>assoc | findstr ".zzz"
.zzz=ZZZFile
No change when trying to open the file.
Associate the file type (ZZZFile, from previous step) with a command. Use the [MS.Learn]: ftype tool for the task. Again, check if the file type is not already associated (this only makes sense if the file type existed before previous step):
e:\Work\Dev\StackOverflow\q052008516>:: As usual, no output means no association
e:\Work\Dev\StackOverflow\q052008516>ftype | findstr ZZZFile
e:\Work\Dev\StackOverflow\q052008516>:: Same thing for txtfile
e:\Work\Dev\StackOverflow\q052008516>ftype | findstr txtfile
txtfile=%SystemRoot%\system32\NOTEPAD.EXE %1
e:\Work\Dev\StackOverflow\q052008516>:: Associate ZZZFile with notepad
e:\Work\Dev\StackOverflow\q052008516>ftype ZZZFile=%SystemRoot%\system32\notepad.exe %1
ZZZFile=C:\WINDOWS\system32\notepad.exe %1
e:\Work\Dev\StackOverflow\q052008516>ftype | findstr ZZZFile
ZZZFile=C:\WINDOWS\system32\notepad.exe %1
Try opening the file again (from Cmd), and voilà:
Summary:
In order to open with Notepad files having .zzz extension, there are only 2 commands that need to be remembered from this whole (and pretty long) answer:
assoc .zzz=ZZZFile
ftype ZZZFile=%SystemRoot%\system32\notepad.exe %1
Notes:
My user has (super) administrative privileges, but I guess they shouldn't impact differently depending where the action is performed from (Cmd or UI (if possible)), in other words users that don't have the required privileges, won't be able to do it, no matter what they would try
Apparently, there is a (pretty dark) nebula on this topic, that my knowledge wasn't yet able to "decipher". In my example, I constantly compare the .zzz results to .txt. Yet a big surprise: Notepad++ and not Notepad is used to open txtfile (.txt only), in spite of the above output
Update #0
I did a little more digging on the .txt mystery. Facts:
FType shows Notepad as opening program
It is actually opened by Notepad++ (in Cmd and PS)
In Choose default apps by file type, Notepad++ is shown
So apparently, it's more than meets the eye (over the years, I got used to MS's way of doing things which in some cases seems to be (but maybe it's me who didn't have all the pieces) illogical).
I've also found out many resources like:
[MS.Technet.Blogs]: Windows 10 – How to configure file associations for IT Pros? which mentions the command:
dism /online /export-defaultappassociations:"file.txt"
[XDADevelopers]: Programatically set default file associations which mentions the reg keys:
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\${EXT}
HKCR\${EXT}
I couldn't find anywhere a clear algorithm of how an executable is chosen to run a file with a certain extension. I can think that the 2 keys above are queried, but I'm 100% sure there's more. Not to mention that I've ran into an even stranger problem (for a regular user on my Win 10), for .py files:
FType (and Assoc) reported everything as above
In Choose default apps by file type, Python was shown (just like in my Super Admin user's case)
Attempting to run the file from Cmd, yielded the dialog at the beginning
It worked from PS
Sadly, I selected Python from the dialog, before taking a look at the registry keys (and now it works), so I can't do any more debugging (and also, switching users is annoying).
Might be related:
[SuperUser]: Windows 10 won't let me set default apps for file extensions
[SuperUser]: Can't change Windows 10 default file type association
[SuperUser]: SSMS wont give up file associations

Adding a context menu item in Windows for a specific file extension

I am trying to add a context menu item to a DLL file. The reason is that I have written an application which retracts and deployed a managed DLL file to the GAC. The application is all good, but now I want the ability to right-click a DLL and just click "copy to GAC".
I've tried to follow instructions as per this question: How add context menu item to Windows Explorer for folders but to no avail. When I right click a DLL, nothing new is appearing.
I've also tried the following: https://winaero.com/blog/add-register-dll-context-menu-commands-for-dll-files-in-windows-10/#comment-22928 - ran the reg file but no result as well.
Maybe there's a hardcoded restriction on DLL files for such actions?
Here's my current registry setup:
Any guidance would be appreciated.
The general steps to achieve this are as follows:
Fire up regedit
Identify the ProgID for your extension - go to HKCR\.yourextension and take note of the default value (in your case, dllfile)
Navigate to HKCU\Software\Classes (for user) or HKLM\Software\Classes (for all users)
Look for a matching key (in your case dllfile) - if it's not there, create it
Ensure it has a sub-key called shell
Add a sub-key to shell named as the command you want (refer to image below)
Add a sub-key to your new key called command
Modify the (Default) value to be the command you want to execute. %1 will give you the path of the file in context (remember to wrap it in " due to potential white-space in the path)
You seem to have done all the above, so you may be doing something wrong, as this is my result after a quick sanity test:
So, here are a few things I can think of that would make it behave non-intuitively:
You're adding this to HKLM rather than HKCU - due to how inheritance works, I do believe adding it to HKLM would require a restart, or at best, a shell restart
You've added this to HKCU but your dll requires elevated permissions to access
You have some silly syntax error somewhere ;)
The sample command I used to test this was a good old boring "C:\Windows\notepad.exe" "%1"
This is based on andromeda947's answer here:
If you have admin rights you can use HKEY_CLASSES_ROOT\SystemFileAssociations\.yourextension, which is simpler as it doesn't require an intermediate ProgID.
Option 1: edit the registry manually
add a new key at HKEY_CLASSES_ROOT\SystemFileAssociations\.yourextension\shell\your menu entry text\command creating any keys you need to in that path (if there's not one for .yourextension add it; if there's not one for shell add it; etc)
set the default value for command (the last key you created) to C:\path\to\yourapp.exe "%1"
Option 2: I made a tool to do this
you can download it here. This is an example of how to register notepad.exe as a context menu item for dll files.
regwincontext.exe dll "notepad it" C:\Windows\notepad.exe

How to include a program on startup?

I would like to have an executable file run at startup, Windows 7.
I was wondering how I may do so directly at the command line or by way of batch file.
Windows provides powershell to automatize this kind of tasks using "command prompt" or scripts.
In the case you are proposing, you can change the registry values that controls startup programs by using the new-item-property cmdlet like this
PS> New-ItemProperty HKM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\ -Name <pretty beautiful name for your app> -Value <executable for your app>
You can also use PowerShell to elliminate or to change keys. But, you know
With big power comes great responsability
On a windows comp
Hit the win + r
A small dialog box appears on bottom left. In the box type
shell:startup
You are automatically redirected to the relevant folder. Just copy past ur program into this folder.
If u have a more malicious intent in mind simply use the copy command to copy the file from its current destination(A USB perhaps) to the location gotten from the aforementioned method.
However there is a slight catch. This only works if ur the admin of the computer. So you would theoretically have to include code to hand your program admin access before copying the file
[Tutorial on how to do it here1

Searching for Command Prompt Parameters?

Is there anyway to search command prompt parameters in a general sense. Or are we hostage to the documentation of such programs? For example in the command prompt I type explorer or notepad... but if I put the first parameter as a file path it will open that file path for me... how am I supposed to know this parameter input exists and perhaps there is a bunch of other parameter fields I am unaware of. Is there anyway to search program parameters systematically?
In Windows programs are responsible for processing their own command line parameters, and they can do so in any way they please. (It is common to hand off tokenization to the C runtime library, but not mandatory.)
This gives the programmer maximum flexibility, but does mean that if the programmer has not documented the command line there is no straightforward way to reverse engineer it after the fact.
(UNIX isn't very much different; the tokenization is handled by the shell, but the rest of the processing is the applications responsibility. In VMS, by contrast, the entire command-line processing is handled by the shell, based on syntax information that must be embedded in the application.)
It is conventional for an application to provide a command-line syntax summary in response to one or more of the following options:
application /?
application -?
application /help
application -help
application --?
application --help
(Arranged approximately from most-common to least-common; the variants with two hyphens are usually only found in software that has been ported from UNIX.)
I haven't looked for actual statistics, but my impression is that the majority of command-line applications (perhaps 80% or more) do provide such a summary. It is less common for GUI applications.
Failing that, you can sometimes find command-line options by looking for strings in the executable file. Microsoft provides a utility that does this, strings.exe, downloadable from their web site. (Of course, knowing the existence of a possible command-line option doesn't necessarily mean you'll be able to figure out what it does!)
If you have access to the source code, or are skilled at disassembly, that may provide another option if you are desperate enough.
No. Though you can always try programname /?.
Notepad takes a single filename only OR takes /p filename ... (you can see the command in txtfiles print entry in the registry).
Here's something from Windows 98 Explorer's it still the same.
Explorer
explorer [/n] [/e][,/root,object][[,/select],subobject]
None Explorer rooted at the Desktop
/n Opens a new window.
/e Explorer View (default if nothing else is on the command line.)
/root,object Starts Explorer with object the top item (normally Desktop is the top item). Eg: explorer /e,/root,c:\Starts Explorer with the C drive as the only drive available.
/select,subobject Selects the specified subobject.
Replaceable parameters are %1 (one) which is the short file or folder name and %l (L) which is the long file name.
/IDLIST
This is an additional parameter that means a Windows internal structure is being passed. eg:
Explorer.exe /e,/idlist,%I
The %I is a replacable parameter representing an IDLIST.
Rooted Views
To open an explorer item that starts with a special folder as the top folder use the following syntax.
Where the special folder is a sub folder of the desktop
explorer /e,root,::{CLSID of special folder}
Where the special folder is a sub folder of another special folder (usually, if not always My Computer)
explorer /e,root,::{CLSID of parent}/::{CLSID of special folder}
Where the special folder is part of the file system
explorer /e,root,path to folder
See Namespaces on the Icons Page for a list of CLSIDs for special folders.
Examples
Note that /select is inconsistent. Sometime the / is required, sometimes it should be left out, and sometimes it doesn't matter.
Starts explorer with the Windows folder opened and selected.
explorer /e,select,c:\windows
Starts explorer with Windows the top level folder and command opened and selected.
explorer /e,/root,c:\windows,select,c:\windows\command
Starts explorer with Windows the top level folder and Tips.txt showing instead of the file listing.
explorer /e,/root,c:\windows,select,c:\windows\tips.txt
Starts explorer with My Computer the top level folder and all branches except for drives collapsed.
explorer /e,/root,::{20d04fe0-3aea-1069-a2d8-08002b30309d}
Starts explorer with C:\ the top level folder.
explorer /e,/root,c:\
Starts the Dial Up Networking folder in folder view.
explorer.exe ::{20d04fe0-3aea-1069-a2d8-08002b30309d}\::{992cffa0-f557-101a-88ec-00dd010ccc48}

FTYPE/ASSOC priority and adding to OpenWithList from the command line

(Not sure if this belongs on superusers, but it seems there is a cmd.exe tag here, so here goes...)
As background, I'm working on a Firefox add-on (This question does not require knowledge of Firefox, btw, as Firefox add-ons can call the command line.) The add-on aims to build different kinds of shortcuts to cmd.exe (especially for the sake of my project https://github.com/brettz9/webappfind which allows files to be opened directly from the desktop into web apps).
Anyways, I'd like to give users the option to associate these shortcuts:
As the default handler for specific file extensions or file types.
To show up within the Open With list of applications (even if the user opts not to make the apps as default handlers)
As far as the default handling, I have found the ftype and assoc (and associate) commands, but I have read that user selections will override their behavior. Is there some way to ensure that I can get priority from the command line in associating file extensions to types and specific executables (until the user changes it again), or if it is not possible, then at least through C++ or the like?
As far as the Open With list:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\<file extension>\OpenWithList
...in my testing (with an exe), this command:
reg add HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.svg\OpenWithList /v d /d D:\wamp\www\webappfind\cplusplus\WebAppFinder-view-mode-Firefox.exe
...did cause the exe file to show up in:
reg query HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.svg\OpenWithList
...but it did not show up when I subsequently right-clicked a file with the ".svg" extension.
I would really appreciate any help with these two points.
REGEDIT4
[HKEY_CURRENT_USER\Software\Classes\Applications\MYFOO.exe\shell\open\command]
#="\"C:\\MYFOO.exe\" \"%1\""
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.myfoo]
"Application"="MYFOO.EXE"
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.myfoo\OpenWithList]
"a"="MYFOO.EXE"
"MRUList"="a"
So I got to an investigation what makes those file associations. It appears that you have to create a mapping from the bare EXE name to the full path as shown in the first two long-ish lines. Then you must only use the EXE name in the .extension branch. Setting the .extension's Application value will give you your default app instantly. Remember, only use APP.EXE, its full path must be defined as above. This was your main error. The "%1" part allows you to customize the parameters of your program so that it doesn't have to be just the opened document in quotes, as shown here. The backslashes are just escape characters for Regedit, you may discard them as you see fit.
The OpenWithList is tricky in the sense that there are letters for entries and just a blind write may overwrite some of the user's favorite apps. One approach would be to call your item "z" to lower the probability of overwriting. The right way would be enumerating the key and giving your app the first free letter. The MRUList is not essential, although it should have each used letter once and yours bumped to the start.
Note about user friendliness: Explorer will cache these values until next reboot. Make sure you update the registry and place exe first and create your file later. Although the caching only fully influences the display of the file and when it is run, the registry is read again and it will execute as you want.
TIP: If you decide to use Regedit instead of reg, the /s parameter skips the confirmation message and applies the values right away. Make sure you use double backslashes in the full path as shown. When preparing your temporary .reg file, make sure you append two CRLF's to the end or a glitch may cause your last line of code to be ignored. This sample starts with REGEDIT4 which signifies an ANSI file. If you need support for Unicode in your app path, you'll have to start the file with Windows Registry Editor Version 5.00 and store it in UTF16. This is already a superior solution to calling reg because there's no way you could get CMD.EXE to process special UTF stuff through the command line without mangling.

Resources