Categories
cmd scripting shortcut Win 7 Win7 Windows Windows 7 Windows Vista Windows7 wscript

Create Windows Shortcuts With a Script at the Command Line

If you are like me you 1) access numerous Windows computers, in my case mainly servers through Remote Desktop; and 2) like to have your Windows desktop setup a certain way.  Here are some examples of a quick and easy way to create shortcuts with a script.  These examples are Visual Basic Scripts (.vbs) and use Windows Script Host to execute.  Create any or all of the examples and execute it from either the command prompt or Start / Run using:

wscript xyz.vbs

Note: These scripts were all tested on Windows 7, Windows 2008 and 2003.  They should run fine on earlier versions of Windows (XP, Vista, 2000, etc.) as well.

Although most of these examples will create shortcuts to Windows Explorer (the last one is a shortcut to the Command Prompt), they are being placed in different locations.  Of course you could modify the examples to launch any program of your choosing.  Additionally you could combine them into one script that could be launched the first time you logon.

For easy reference I highlighted the values you may want to change to tailor the script to your needs.

Windows 7, Vista and Windows 2008 Server note: You will probably have to execute these with administrative rights.  One way to do this is to launch a command prompt (the old fashioned way – Start [All] Programs / Accessories / Command Prompt) using right-click and selecting “Run As Administrator.”

Example 1 – Shortcut to Windows Explorer in the “All Users” Desktop folder.  I named the script Explorer_Shortcut_on_AU_Desktop.vbs.

set WshShell = WScript.CreateObject("WScript.Shell" )
strDesktop = WshShell.SpecialFolders("AllUsersDesktop" )
set oShellLink = WshShell.CreateShortcut(strDesktop & "Windows Explorer.lnk" )
oShellLink.TargetPath = "%SYSTEMROOT%explorer.exe"
oShellLink.WindowStyle = 1
oShellLink.IconLocation = "%SystemRoot%explorer.exe"
oShellLink.Description = "Windows Explorer"
oShellLink.WorkingDirectory = "%HOMEPATH%"
oShellLink.Save

Example 2 – Shortcut to Windows Explorer in the “All Users” Start Menu folder.  I named the script Explorer_Shortcut_in_AU_Startmenu.vbs.

set WshShell = WScript.CreateObject("WScript.Shell" )
strStartMenu = WshShell.SpecialFolders("AllUsersStartmenu" )
set oShellLink = WshShell.CreateShortcut(strStartMenu & "Windows Explorer.lnk" )
oShellLink.TargetPath = "%SYSTEMROOT%explorer.exe"
oShellLink.WindowStyle = 1
oShellLink.IconLocation = "%SystemRoot%explorer.exe"
oShellLink.Description = "Windows Explorer"
oShellLink.WorkingDirectory = "%HOMEPATH%"
oShellLink.Save

Example 3 – Shortcut to Windows Explorer in the “All Users” Startup folder.  I named the script Explorer_Shortcut_in_AU_Startup.vbs.  This will cause one instance of Windows Explorer to launch during logon.  If you’re like me you will be using it anyway, so why not have it open automatically.

set WshShell = WScript.CreateObject("WScript.Shell" )
strStartup = WshShell.SpecialFolders("AllUsersStartmenu" )
set oShellLink = WshShell.CreateShortcut(strStartup & "programsstartupWindows Explorer.lnk" )
oShellLink.TargetPath = "%SYSTEMROOT%explorer.exe"
oShellLink.WindowStyle = 1
oShellLink.IconLocation = "%SystemRoot%explorer.exe"
oShellLink.Description = "Windows Explorer"
oShellLink.WorkingDirectory = "%HOMEPATH%"
oShellLink.Save

Example 4 – Shortcut to Windows Explorer in the “Current User” Quick Launch toolbar.  I named the script Explorer_Shortcut_in_CU_QuickLaunch.vbs.

set WshShell = WScript.CreateObject("WScript.Shell" )
strStartup = WshShell.SpecialFolders("AppData" )
set oShellLink = WshShell.CreateShortcut(strStartup & "MicrosoftInternet ExplorerQuick LaunchWindows Explorer.lnk" )
oShellLink.TargetPath = "%SYSTEMROOT%explorer.exe"
oShellLink.WindowStyle = 1
oShellLink.IconLocation = "%SystemRoot%explorer.exe"
oShellLink.Description = "Windows Explorer"
oShellLink.WorkingDirectory = "%HOMEPATH%"
oShellLink.Save

Example 5 – Shortcut to Command Prompt in the Quick Launch toolbar for you, the current user.  I named the script CMD_Shortcut_in_CU_QuickLaunch.vbs.

set WshShell = WScript.CreateObject("WScript.Shell" )
strStartup = WshShell.SpecialFolders("AppData" )
set oShellLink = WshShell.CreateShortcut(strStartup & "MicrosoftInternet ExplorerQuick LaunchCommand Prompt.lnk" )
oShellLink.TargetPath = "%SYSTEMROOT%system32cmd.exe"
oShellLink.WindowStyle = 1
oShellLink.Hotkey = "Ctrl+Alt+C"
oShellLink.IconLocation = "%SystemRoot%system32cmd.exe"
oShellLink.Description = "Windows Command Prompt"
oShellLink.WorkingDirectory = "%HOMEPATH%"
oShellLink.Save

See also: