I want to create generic shortcuts in Windows 10 using a target path
extension of the shell path, something like
%windir%\explorer.exe shell:AppData ..\Local\Temp
%windir%\explorer.exe shell:AppData works by itself, takes me to roaming userfiles.
I could use
%windir%\explorer.exe shell:UsersFilesFolder
which would take me to %UserProfile% and append from there (if I could find out how) only it would be handy to be able to go up a level if possible as well.
I can't work out
How to append a further couple directories into the shortcut target path
How to go up one directory first (..?)
What is the syntax to make this work?
First of all, %Temp% might not be the same as %LOCALAPPDATA%\Temp!
The way to create a perfect shortcut to %Temp% is not that easy, ideally the .lnk should only contain a EXP_SZ_LINK:EXP_SZ_LINK_SIG block with the %Temp% string. You have to manually delete the ItemIdList block to get a .lnk file like that. %Temp% is extra complicated because it does not have a special folder canonical name you can use with the shell: protocol.
I don't believe the shell: protocol supports .. nor . path components.
shell:AppData ..\Local is also wrong because the local appdata folder might be somewhere else (< Windows Vista used different names) and a better command would be %windir%\explorer.exe "shell:LocalAppData" (and in turn %windir%\explorer.exe "shell:Local AppData\Temp") but all of those commands have other issues.
First of all, Explorer might not be the users shell and you risk not obeying the users preferences.
Another problem is that a .lnk file contains the attributes of its target and because the link actually points to a .exe file your .lnk file will not have the FILE_ATTRIBUTE_DIRECTORY bit set for its target attribute and the shell will not understand that it points to a folder. A .lnk that points to a folder will sometimes open in the same window when navigating the shell instead of opening a new file browser window.
The .lnk binary format is documented and by breaking the rules a little bit I have been able to create a link that points to a file/folder inside a special shell folder by combining a EXP_SPECIAL_FOLDER block with a manipulated ItemIdList but for whatever reason this trick does not work for deeper paths.
A EXP_SPECIAL_FOLDER block and a empty ItemIdList is the only way to create shortcuts to special folders that is guaranteed to work on all systems but you have to create it manually, the IShellLink implementation adds system specific blocks that might break things if you try to use the link on another system.
The .lnk format has not changed much since Windows 95 and there is simply no easy way to create shortcuts relative to special folders that also work when they are copied to other systems. The relative path string in a .lnk is relative to the .lnk file itself and is not helpful in this case.
I would recommend that you simply create the .lnk on the target system in your installer/application and let IShellLink fill in as much information as possible behind your back.
Related
There is a network share used as repository in my company and it is quite difficult to navigate through it and find certain files. Some of these files get a new name every day , usually the date changes, which makes it impossible to create shortcuts to them. Usually these are excel or word files. Is there a way I can create a shortcut to that file even though the date has changed on the name of the file?
If you definitely have to use a shortcut (lnk file) for this the only workaround that comes to mind is pointing the shortcut to an environment variable and changing that programatically (wildcards are not supported in lnk files afaik).
However I assume that in most cases what you want is not really a shortcut in its technical definition but rather a way to open the file you want with a double click. In this case it would be a lot easier to just use a simple script that figures out what the name of the file currently is (by whatever rules you use manually) and launch it.
Should be doable in vbscript or powershell (maybe even batch) just fine as long as there is some logical way to determine which file is the right one (e.g. always the current date, always the file where the date is newest, the only file with extension xlsx, ...)
What I need is quite usual, which goes like this:
On a windows OS(in my case, win7), we can create a shortcut for a certain program(e.g. *.exe, *.bat ...), and then use right-click to bind an accelerate keys combo for this shortcut.
So I created a .bat file for starting my python.exe in cmd mode, then created a shortcut for this .bat and added ctrl + alt + Num 9 for it in order to start python more conveniently.
So far this works, but it always starts python with default directory:
C:\windows\system32.
I wish that it could start exactly from the currently active folder's directory(e.g. if I'm in D:\certain_python_modules\module_1 and input this key-board-shortcuts, I need that in python, os.getcwd() prints exactly the same directory), what should I do?
It's not really clear what you're doing and want to do.
There's no global currently active folder, every process has its current folder (it's called current directory). It can be programmatically specified when you launch a process, and it can be changed after its launch, but by default it is inherited by the calling process.
Specifically, every command prompt has its own current folder
When you press your ctrl + alt + Num 9 sequence it is detected by the shell, and the shell executes the shortcut (a.ka. as link) that is associated with it. The program that you were currently working with is completely ignored. The current directory of the process launched is set to either:
The 'From' field in the shortcut's property sheet, if it is set
The shortcut's file location, otherwise
When you say I'm in D:\certain_python_modules\module_1, do you mean in a command prompt or in an explorer/file explorer window ?
Either way, you can't do what you want with any standard Windows feature, you could probably do it with some work (maybe even not much, I don't know) with something like AutoHotKey or a program of your own.
If you are working in a command prompt though you can do a thing analogue to what you're trying by using a command rather than a keyboard shortcut: either:
type the full path of the program,
or add the command's directory to your PATH environment variable and type its name,
or, if the program's name is long and you want to type less, make a batch file that just calls your program, give it a short name (e.g. py.bat), and add the batch file's directory to your PATH variable.
Whatever of these methods you use to call it, the called program (python, in your case) will have its current directory set to the the directory from where you're calling it.
you could use os.getcwd() method in os module of python and then, use os.system()
to give system command to change your directory
it is kind of an indirect approach though.
Hope it helps
I have a filesystem and there seems to be two different folder names for the same folder. On the DOS prompt, I don't see any directories unless I use /a.
What is going on here and how may I implement this kind of GUID/Friendly names scheme on my own?
In Windows Explorer, the folder name looks like E:\Mediadatabase\Storage\ but if I click in the address field, I see E:\MediaDatabase\1f9b78f5-0dcd-452a-9404-a45d0775b12f\
Dos prompt
DOS prompt
(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.
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?