Hi Stukely and Paul,
Have tried the following coding and it seems to work. Would be most grateful for your comments on it:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
‘Create shortcuts to program and to online database on desktop if they do not exist
CreateShortcuts()
Dim DirInfo As System.IO.DirectoryInfo
‘Creates LIFEnet directory if it does not exist
If Not DirExists("C:\LIFEnet") Then
DirInfo = System.IO.Directory.CreateDirectory("c:\LIFEnet")
End If
‘Creates LIFEnet\Templates directory if it does not exist
If Not DirExists("C:\LIFEnet\Templates") Then
DirInfo = System.IO.Directory.CreateDirectory("C:\LIFEnet\Te mplates")
‘Copies Word Template into directory
Try
My.Computer.Network.DownloadFile("http://63.134.211.113/LIFEnetMail/LIFEnet Letter Template.dot", "C:\LIFEnet\Templates\LIFEnet Letter Template.dot", _
"", "", False, 10000, True)
Catch ex As Exception
MessageBox.Show("Unable to copy Letter Template" & vbCrLf & ex.Message)
End Try
End If
‘Creates LIFEnet\Documents directory if it does not exist
If Not DirExists("C:\LIFEnet\Documents") Then
DirInfo = System.IO.Directory.CreateDirectory("c:\LIFEnet\Do cuments")
End If
End Sub
Private Function DirExists(ByVal DName As String) As Boolean
‘Check if directory exists
Dim sDummy As String
Dim RightStr As String
On Error Resume Next
RightStr = Strings.Right(DName, 1)
If RightStr <> "\" Then DName = DName & "\"
sDummy = Dir$(DName & "*.*", vbDirectory)
DirExists = Not (sDummy = "")
End Function
Public Sub CreateShortcuts()
Dim objShell, strProgramsFolder, strDesktopFolder, objProgramShortcut, objURLShortcut, objFSO
objShell = CreateObject("WScript.Shell")
objFSO = CreateObject("Scripting.FileSystemObject")
strDesktopFolder = objShell.SpecialFolders("Desktop")
strProgramsFolder = objShell.SpecialFolders("Programs")
'Create shortcut to program
If Not objFSO.FileExists(strDesktopFolder & "\LIFEnetMail Program.appref-ms") Then
Dim ProgramPath = strProgramsFolder & "\LIFEnet Software\LIFEnetMail Program.appref-ms"
Dim DesktopPath = strDesktopFolder & "\LIFEnetMail Program.appref-ms"
Try
System.IO.File.Copy(ProgramPath, DesktopPath, True)
Catch e As Exception
Throw e
End Try
End If
'Create shortcut to online database
If Not objFSO.FileExists(strDesktopFolder & "\LIFEnet Online Database.url") Then
objURLShortcut = objShell.CreateShortcut(strDesktopFolder & "\LIFEnet Online Database.url")
objURLShortcut.TargetPath = "http://63.134.211.113/login.asp"
objURLShortcut.Save()
End If
objShell = Nothing
objFSO = Nothing
End Sub
The only thing is that, if the user deletes the shortcuts, they are created again when the program runs. Suppose I could create a text file with, say, an integer value in it (starting with 1). After shortcuts are created, this value is changed to 0 and the program checks this value when it runs. If 1, creates shortcuts, otherwise does nothing.
I am sure there is more elegant way of doing this!
Anyway, would much appreciate you view of the coding.
Regards
Brian
|