* Using Windows Scripting Host create a shortcut (link to a file or URL)
* Example:
* 1.) DO CreateShortCut WITH "Notepad.lnk", "notepad.exe"
* 2.) DO CreateShortCut WITH "Microsoft Web Site.URL", "[URL unfurl="true"]http://www.microsoft.com"[/URL]
LPARAMETERS tcShortCutName, tcTargetPath
IF PCOUNT() < 2
MESSAGEBOX("Not enough parameters.")
RETURN
ENDIF
LOCAL lcxDirectory, loWshShell, loShortCut, llNormalShortCut
* Save current directory.
lcxDirectory = SET("Directory")
* Determine if this is a URL shortcut or a normal (lnk) shortcut.
llNormalShortCut = .F.
lcExt = UPPER(ALLTRIM(JUSTEXT(tcShortCutName)))
IF lcExt = "LNK"
llNormalShortCut = .T.
ENDIF
loWshShell = CreateObject( "WScript.Shell" )
* added desktop variable so you can see how to send the short-cuts to a different
* folder, let's say a network folder that can be shared by several users. This is handy
* if you create weekly / monthly reports on the network and you want to give a group of
* users access to them.
llDesktop = .T.
IF llDesktop
SET DIRECTORY TO (loWshShell.SpecialFolders("Desktop"))
ELSE
SET DIRECTORY TO O:\office\shortcuts
ENDIF
loShortCut = loWshShell.CreateShortcut( tcShortCutName )
loShortCut.TargetPath = tcTargetPath
* The following properties are only available for normal short cuts.
IF llNormalShortCut
* Below are other properties and examples of setting them.
* loShortCut.IconLocation = "notepad.exe, 0"
loShortCut.Description = "Currently running script."
* add hot key if you like.
* loShortCut.Hotkey = "ALT+CTRL+F"
loShortCut.Hotkey = ""
loShortCut.WindowStyle = 7 && minimized
loShortCut.WorkingDirectory = ADDBS(JUSTPATH(m.tcTargetPath))
loShortCut.IconLocation = tcTargetPath
* Display full path of the executable
* ?loShortCut.Fullname
ENDIF
loShortCut.Save
* move back to your starting directory
SET DIRECTORY TO (lcxDirectory)