Torna al Thread

Public Class Form1 Private Function CreateShortCut(ByVal shortcutName As String, ByVal creationDir As String, ByVal targetFullpath As String, ByVal workingDir As String, ByVal iconFile As String, ByVal iconNumber As Integer) As Boolean Try If Not IO.Directory.Exists(creationDir) Then Dim retVal As DialogResult = MsgBox(creationdir & " does not exist. Do you wish to create it?", MsgBoxStyle.Question Or MsgBoxStyle.YesNo) If retVal = DialogResult.Yes Then IO.Directory.CreateDirectory(creationDir) Else Return False End If End If Dim shortCut As IWshRuntimeLibrary.IWshShortcut Dim wShell As WshShell = New WshShell() shortCut = CType(wShell.CreateShortcut(creationDir & "\" & shortcutName & ".lnk"), IWshRuntimeLibrary.IWshShortcut) shortCut.TargetPath = targetFullpath shortCut.WindowStyle = 1 shortCut.Description = shortcutName shortCut.WorkingDirectory = workingDir shortCut.IconLocation = iconFile & ", " & iconNumber shortCut.Save() Return True Catch ex As System.Exception Return False End Try End Function Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim myBool As Boolean 'Sarà uguale a true se l'operazione è andata a buon fine, false se l'operazione non ha creato il collegamento myBool = CreateShortCut("My Application", System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop), Application.ExecutablePath, Application.StartupPath, "myAppExtensions.dll", 4) End Sub End Class
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5