CreateShortcut Method

 

Description

 

Creates a new shortcut, or opens an existing shortcut.

 

PowerBASIC Syntax

 

METHOD CreateShortcut ( _

BYVAL bstrPathName AS STRING _

) AS IDispatch

 

Arguments

 

bstrPathName

BSTR. The pathname of the shortcut to create.

 

Return Value

 

IDispatch. Either a reference to a IWshShortcut interface or a IWshURLShortcut interface.

 

Remarks

 

Simply calling the CreateShortcut method does not result in the creation of a shortcut. The shortcut object and changes you may have made to it are stored in memory until you save it to disk with the Save method. To create a shortcut, you must:

 

1.Create an instance of a IWshshell interface.
2.Get a reference to a IWshShortcut interface calling the CreateShortcut method.
3.Initialize its properties.
4.Save it to disk with the Save method.

 

Example [PowerBASIC]

 

#INCLUDE "WSHOM.INC"

 

' Creates an instance of the Windows Script Host

LOCAL pWsh AS IWshShell

pWsh = NEWCOM "WScript.Shell"

 

' Creates a shortcut programatically (if it already exists, CreateShortcut opens it)

LOCAL pLnk AS IWshShortcut

pLnk = pWsh.CreateShortcut(UCODE$(EXE.PATH$ & "Test.lnk"))

 

' Sets variuos properties and saves them to disk

pLnk.Description = UCODE$("Hello world")

pLnk.WorkingDirectory = UCODE$(EXE.PATH$)

pLnk.Arguments = UCODE$("/c")

pLnk.HotKey = UCODE$("Ctrl+Alt+e")

pLnk.IconLocation = UCODE$(EXE.PATH$ & "PROGRAM.ICO,0")

pLnk.RelativePath = UCODE$(EXE.PATH$)

pLnk.TargetPath = UCODE$(EXE.PATH$ & "EX_WHLNK_CreateShortcut.EXE")

pLnk.WindowStyle = %WshNormalFocus

pLnk.Save

 

' Get the parameters to to see if they have changed

STDOUT "Shortcut description: " & ACODE$(pLnk.Description)

STDOUT "Shortcut working directory: " & ACODE$(pLnk.WorkingDirectory)

STDOUT "Shortcut arguments: " & ACODE$(pLnk.Arguments)

STDOUT "Shortcut hot key: " & ACODE$(pLnk.HotKey)

STDOUT "Shortcut icon location: " & ACODE$(pLnk.IconLocation)

STDOUT "Shortcut target path: " & ACODE$(pLnk.TargetPath)

STDOUT "Shortcut window style: " & FORMAT$(pLnk.WindowStyle)

 

Example [PowerBASIC]

 

#INCLUDE "WSHOM.INC"

 

' Create an instance of the Windows Script Host

LOCAL pWsh AS IWshShell

pWsh = NEWCOM "WScript.Shell"

 

' Create a shortcut programatically (if it already exists, CreateShortcut opens it)

LOCAL pLnk AS IWshURLShortcut

pLnk = pWsh.CreateShortcut(UCODE$(EXE.Path$ & "Microsoft Web Site.url"))

 

' Set variuos properties and saves them to disk

pLnk.TargetPath UCODE$("http://www.microsoft.com")

pLnk.Save

 

' Get the parameters to to see if they have changed

STDOUT "Shortcut full name: " & ACODE$(pLnk.FullName)

STDOUT "Shortcut target path: " & ACODE$(pLnk.TargetPath)

 

Valid XHTML 1.0 Transitional