If I have a file named "C\Test\mypic.jpg", can I create a shortcut with path "C\Test2\mypic.jpg"? Windows always seems to add a ".lnk" suffix, which is unwanted in my case.
Link in this case can mean several things but we can unpack all the possible scenarios:
A shortcut (.lnk file). These files must have the .lnk extension because the file extension is how Windows decides which handler to invoke when you double-click/execute the file. If you create a shortcut to a jpg file the real name can be link.jpg.lnk but the user will see the name as link.jpg in Explorer because .lnk is a special extension that is hidden.
A symbolic link (symlink). These are links on the filesystem level and can have any extension. mklink "c:\mylink.jpg" "c:\file.jpg"
A hardlink. This is another name for the same file (alias), it does not create a shortcut. mklink /H "c:\anothername.jpg" "c:\file.jpg"
Related
I am launching a script with a powershell shortcut (C:\Windows....\powershell.exe -file 'D:\powershell\script.ps1').
Is there a way to make script change its current location to location of said shortcut?
Example: Script itself is in D:\powershell\ and the shortcut is in C:\Work\Project1. I need the script to cd to "C:\Work\Project1\".
Thanks
You can make a shortcut that starts in whatever directory it's located in. All you have to do is modify the "Starts In" property of the shortcut, and blank it out. That's right. Set it to nothing.
Then, when you want to invoke the shortcut, navigate to the folder (directory) where it's located before invoking it. I use this technique for a shortcut that launches powershell but doesn't launch a script. I haven't tested it with a shortcut that launches a script.
Walter Mitty's helpful answer provides an effective solution, provided that the shortcut file is opened from either the Desktop or File Explorer.
This answer provides background information.
You must configure the desired working directory as part of the shortcut file, because the script you invoke knows nothing about the shortcut that invoked it.
Therefore, to configure a specific working directory (e.g., C:\Work\Project1), specify it in the shortcut file's Properties dialog in the Start in: field.
In case you want to update a shortcut file's (*.lnk) working directory programmatically, use the technique from this answer with the .WorkingDirectory property.
Note: In both cases, only an absolute path can be configured as the working directory: File Explorer only allows you to enter an absolute path anyway, and while the programmatic method allows you to assign a relative path, it is instantly resolved to an absolute one, relative to the shortcut's location.
To make the shortcut's own directory the working directory, you can blank out the Start in: field / .WorkingDirectory property, but note the limitations:
Only works when such a shortcut is either opened from either the Desktop or from File Explorer.
By contrast, opening it from the taskbar or (pre-Windows 10 only) the Start Menu, the working directory is $env:windir\System32 (typically, C:\Windows\System32).
If the shortcut targets an application (rather than a document), as in this case, that application invoked by the shortcut - including cmd.exe and powershell.exe - starts in the configured / implied working directory.
Caveat re cmd.exe: If the working directory is specified as as a UNC path, cmd.exe won't be able to change to that directory; as a workaround, use a path with a mapped drive instead (but, obviously, that drive must be mapped at the time the shortcut is opened).
You can use the TargetPath property of the shortcut (maybe do a get-childitem $psscriptroot where name is like scriptname and extension is like .lnk) with the set-location cmdlet
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/set-location?view=powershell-6
I am looking for a shortcut to copy the path of a file in Mac OS. I generally require it to copy paste in editor.
All you need to do to copy any items path name directly to the clipboard from anywhere in the file system:
Navigate to the file or folder you wish to copy the path for Right-click (or Control+Click, or a Two-Finger click on trackpads) on the file or folder in the Mac Finder
While in the right-click menu, hold down the OPTION key to reveal the “Copy (item name) as Pathname” option, it replaces the standard Copy option
Once selected, the file or folders path is now in the clipboard, ready to be pasted anywhere
The copied pathname is always the complete path, it’s not relative.
More details on the following link: http://osxdaily.com/2015/11/05/copy-file-path-name-text-mac-os-x-finder/
Try with shortcut command+option+C:
Cmd-Opt-C
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.
I need a code for cmd.exe for creating a shortcut on any user's desktop.
If the application will be in the same folder on all machines (like C:\Program Files\Software\Start.exe) then create a shortcut, place it on a network drive, or in the .cmd file's folder, and simply just copy it to C:\%username%\Desktop
I need to set an icon for my batch file OR for the shortcut of my batch file , using the nsis installer.
Can an icon be set only of a shortcut , or can i set the icon of the main batch file whose shortcut needs to be created.
The following code isn't working:
I have a folder MyAccountSoftware, my installer will compile the files of this folder into the exe file.
This folder has these two files :-
---MyAccountSoftware
|______Account.BAT
|______Account.ico
SetOutPath $INSTDIR\
File "MyAccountSoftware\Account.BAT"
CreateShortCut "$INSTDIR\Account.lnk" "$INSTDIR\Account.BAT" "$INSTDIR\Account.ico"
This code, just copies the file Account.BAT into the required $INSTDIR, and creates a shortcut -
Account.Ink in the $INSTDIR, but doesn't set the icon of the Shortcut.
Please help.
Batch files cannot have custom icons. When creating the shortcut, even if you don't need a parameter you still need to provide a empty string:
CreateShortCut "$INSTDIR\Account.lnk" "$INSTDIR\Account.BAT" "" "$INSTDIR\Account.ico"