.CreateShortcut

Create or edit a Windows Shortcut

Syntax
      objShell.CreateShortcut(strLinkFile)
      ShortcutObject.property = "Your Value"

Key
   objShell   A WScript.Shell object
   ShortcutObject  An existing shortcut object

Examples

   Set objShell = WScript.CreateObject("WScript.Shell")
   Set lnk = objShell.CreateShortcut("C:\MyShortcut.LNK")
   
   lnk.TargetPath = "C:\Program Files\MyApp\MyProgram.EXE"
   lnk.Arguments = ""
   lnk.Description = "MyProgram"
   lnk.HotKey = "ALT+CTRL+F"
   lnk.IconLocation = "C:\Program Files\MyApp\MyProgram.EXE, 2"
   lnk.WindowStyle = "1"
   lnk.WorkingDirectory = "C:\Program Files\MyApp"
   lnk.Save
   'Clean up 
Set lnk = Nothing

Similarly in PowerShell:

   $objShell = New-Object -ComObject WScript.Shell
   $lnk = $objShell.CreateShortcut("$home\Desktop\DemoShortcut.lnk")
   $lnk.TargetPath = "C:\demo\application.exe"
   # add any arguments
   $lnk.Arguments = "-accepteula"
   # minimize the window  (3=Maximized 7=Minimized  4=Normal)
   $shortcut.WindowStyle = 7
   # Set an icon   (can also pull from a DLL 'shell32.dll,8')
   $lnk.IconLocation = "C:\demo\myicon.ico"
   # Set a shortcut key
   $lnk.Hotkey = "ALT+CTRL+R"
   $lnk.Save() 

The 'Description' property corresponds to the shortcut "Comment" field, this will be displayed in a tool-tip.

HotKey mappings are only usable if the shortcut is on the Desktop or in the Start Menu.
Valid hot key-options:
"ALT+", "CTRL+", "SHIFT+", and "EXT+".
"A" .. "Z", "0" .. "9", "Back", "Tab", "Clear", "Return", "Escape", "Space", and "Prior".

Internet Shortcuts
Unlike file/folder shortcuts, Internet Explorer Favourite (.URL) files are simple text files which you can create with a couple of ECHO statements:

Echo [InternetShortcut] > demo.url
Echo URL=https://ss64.com/ >> demo.url

“Our life is frittered away by detail... simplify, simplify” - Henry David Thoreau

Related VBScript commands

Arguments, display - WshArguments.Item
Q263324 - Shortcut command truncates path names if the target does not currently exist.
Equivalent Windows CMD command: SHORTCUT - Create a windows shortcut (.LNK file)


 
Copyright © 1999-2023 SS64.com
Some rights reserved