wscript xyz.vbsNote: 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" )Example 2 - Shortcut to Windows Explorer in the "All Users" Start Menu folder. I named the script Explorer_Shortcut_in_AU_Startmenu.vbs.
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
set WshShell = WScript.CreateObject("WScript.Shell" )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.
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
set WshShell = WScript.CreateObject("WScript.Shell" )Example 4 - Shortcut to Windows Explorer in the "Current User" Quick Launch toolbar. I named the script Explorer_Shortcut_in_CU_QuickLaunch.vbs.
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
set WshShell = WScript.CreateObject("WScript.Shell" )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.
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
set WshShell = WScript.CreateObject("WScript.Shell" )See also:
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
Hi, it's great article. Can you advice me how to call command (TargetPath) like
ReplyDeletecmd /C start http://localhost/page.html
?
If I run the script, It create a shortcut with target like
"c:\cmd \C start http:\\localhost\page.html"
Thank you, BR Jan.
strStartup is not working it says command not recognized
ReplyDelete