Tuesday, 13 April 2010

Some vbs scripts to create shortcuts in your Windows

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 & "\programs\startup\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 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 & "\Microsoft\Internet Explorer\Quick Launch\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 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 & "\Microsoft\Internet Explorer\Quick Launch\Command Prompt.lnk" )
oShellLink.TargetPath = "%SYSTEMROOT%\system32\cmd.exe"
oShellLink.WindowStyle = 1
oShellLink.Hotkey = "Ctrl+Alt+C"
oShellLink.IconLocation = "%SystemRoot%\system32\cmd.exe"
oShellLink.Description = "Windows Command Prompt"
oShellLink.WorkingDirectory = "%HOMEPATH%"
oShellLink.Save

2 comments:

  1. Thanks for sharing your info. I really appreciate your efforts and I will be waiting for your further write ups thanks once again.
    youtube html5 player

    ReplyDelete
  2. how to remove vbs scripts shortcuts from my Windows

    ReplyDelete