Wednesday, August 23, 2006

SNTT - How to create a Windows shortcut from LotusScript using Windows Scripting Host calls

Recently I had a need to deploy a Microsoft Access application to a number of users. I needed to give them each their own copy of the database and give them a shortcut to it. There are a number of ways to achieve this, but I decided the easiest would be to just use some Windows Scripting Host calls. Here is a short snippet of code that will get the location of the currently logged in user's My Documents and Desktop folders, copy a file from a network drive (P in this case) to the My Documents, then create a shortcut to it on the user's desktop.
Dim sDesktop As String
Dim sMyDocs As String

Dim oShell As Variant
Dim oShortcut As Variant
Dim oFS As Variant

Set oShell = CreateObject("WScript.Shell")
Set oFS = CreateObject("Scripting.FileSystemObject")

sDesktop = oShell.SpecialFolders("Desktop")
sMyDocs = oShell.SpecialFolders("MyDocuments")

'Copy the file
Filecopy "P:\Charles\BPS Barcodes.mdb", sMyDocs & "\BPS Barcodes.mdb"

'Create shortcut
Set oShortcut = oShell.CreateShortcut(sDesktop & "\BPS Barcodes.lnk")
oShortcut.TargetPath = sMyDocs & "\BPS Barcodes.mdb"

Messagebox "Installation successful.", 0, "BPS Barcodes"
This LotusScript was converted to HTML using the ls2html routine,
provided by Julian Robichaux at


No comments:

Post a Comment