SHORTCUT - CMD
Overview
The SHORTCUT
command in Windows CMD is used to create, modify, or delete shortcuts to programs, files, and directories. It is a powerful tool for automating desktop organization and can be effectively used in scripts to manage shortcuts systematically.
Syntax
The basic syntax for using the SHORTCUT
command is as follows:
SHORTCUT /F:filename /A:action /T:target /P:parameters /W:workingdir /I:iconfile /H:hotkey /R:runstyle /K:description
- /F:filename – Specifies the shortcut file path.
- /A:action – Defines the action (create, modify, delete).
- /T:target – Target path of the file or application.
- Other parameters are optional and used to specify further details of the shortcut.
Options/Flags
- /F:filename – Path and name of the shortcut file (e.g.,
c:\path\shortcut.lnk
). - /A:action – Action to perform:
create
,modify
, ordelete
. - /T:target – Target path that the shortcut will point to.
- /P:parameters – Parameters to pass to the target when it’s launched.
- /W:workingdir – The working directory from which the target is run.
- /I:iconfile – File that contains the icon for the shortcut.
- /H:hotkey – Defines a hotkey for the shortcut for quick access.
- /R:runstyle – Style of window in which the target will run (
1
for normal,3
for maximized,7
for minimized). - /K:description – Description for the shortcut.
Examples
Creating a Shortcut:
SHORTCUT /F:"%USERPROFILE%\Desktop\MyApp.lnk" /A:create /T:"C:\Program Files\MyApp\MyApp.exe" /W:"C:\Program Files\MyApp" /I:"C:\Program Files\MyApp\MyIcon.ico" /R:1
Modifying a Shortcut:
SHORTCUT /F:"%USERPROFILE%\Desktop\MyApp.lnk" /A:modify /T:"C:\NewLocation\MyApp.exe"
Deleting a Shortcut:
SHORTCUT /F:"%USERPROFILE%\Desktop\MyApp.lnk" /A:delete
Common Issues
- Permission Issues: You might encounter permission errors if the CMD is not run as an administrator when attempting to create shortcuts in system directories.
- Incorrect Path: Ensure paths are correctly specified. Use quotations for paths that contain spaces.
Integration
SHORTCUT
command can be used in batch files and scripts to prepare a new user environment by auto-setting the necessary program links on the desktop or start menu. For example:
FOR %%A IN (Word, Excel, PowerPoint) DO (
SHORTCUT /F:"%USERPROFILE%\Desktop\%%A.lnk" /A:create /T:"C:\Program Files\Microsoft Office\%%A.exe"
)
Related Commands
- MKLINK – Used for creating symbolic links, which is somewhat related but serves different purposes in file management.
- COPY – Often used alongside
SHORTCUT
to relocate files or configurations in preparation for creating a shortcut.
For a deeper understanding and more complex scenarios, refer to the official Microsoft documentation for scripting and batch file interactions.