technology

VBScript for creating a shortcut

I wrote some VBScript for the first time in my life. Here’s a script that creates a shortcut on the desktop, based heavily on the answers here. It’s pretty rough, but does the job for now:

set objWSHShell = CreateObject("WScript.Shell")

' First argument is the name of the shortcut
' Argument 2 is path to target
sScriptDir = Replace(WScript.ScriptFullName, WScript.ScriptName, "")
sShortcut = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(0))
sDesktop = objWSHShell.SpecialFolders("Desktop")
sTargetPath = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(1))
set fso = CreateObject("Scripting.FileSystemObject")
sTargetDir = fso.GetParentFolderName(sTargetPath)

set objSC = objWSHShell.CreateShortcut(sDesktop & "\" & sShortcut) 
objSC.TargetPath = sTargetPath
objSC.IconLocation = sScriptDir & "Slick_icon.ico"
objSC.WorkingDirectory = sTargetDir
objSC.Save
Advertisements
Standard

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s