Imports System.Windows.Forms
Imports Microsoft.Win32
Public Class NewLinkDialog
Private Function GetOpenCommandLine(ByVal Extension As String) As String
Dim RegKey As RegistryKey
RegKey = Registry.ClassesRoot.OpenSubKey(Extension)
If RegKey Is Nothing Then
Return Nothing
End If
Dim AppKeyName As String = RegKey.GetValue("")
RegKey = Registry.ClassesRoot.OpenSubKey(AppKeyName & "\shell\open\command")
If RegKey Is Nothing Then
Return Nothing
End If
Return RegKey.GetValue("")
End Function
Public ReadOnly Property FileName() As String
Get
Return txtFile.Text
End Get
End Property
Public ReadOnly Property Arguments() As String
Get
Return txtArguments.Text
End Get
End Property
Public ReadOnly Property VocalCommand() As String
Get
Return txtVocalCommand.Text
End Get
End Property
Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
If Not IO.
File.
Exists(txtFile.
Text) Then
MessageBox.Show("Questo file non esiste!", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
If String.IsNullOrEmpty(txtVocalCommand.Text) Then
MessageBox.Show("Riempire tutti i campi necessari!", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
Me.DialogResult = System.Windows.Forms.DialogResult.OK
Me.Close()
End Sub
Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.Close()
End Sub
Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click
Dim Open As New OpenFileDialog
Open.Filter = "Applicazioni|*.exe|Tutti i files|*.*"
If Open.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim File As String = Open.
FileName
If IO.
Path.
GetExtension(File) = ".exe" Then
Else
Dim CommandLine
As String = GetOpenCommandLine
(IO.
Path.
GetExtension(File))
Dim Program As String
Dim Arguments As String
If CommandLine Is Nothing Then
Exit Sub
End If
Program = CommandLine.Remove(CommandLine.IndexOf(".exe") + 4)
Arguments = CommandLine.Remove(0, Program.Length)
Program = Program.Replace(Chr(34), "")
If Arguments.Split(Chr(34)).Count Mod 2 = 0 Then
Arguments = Arguments.Remove(Arguments.IndexOf(Chr(34)), 1)
End If
If IO.
File.
Exists(Program
) Then
Arguments
= Arguments.
Replace("%1",
File)
Arguments
= Arguments.
ToLower.
Replace("%l",
File)
txtFile.Text = Program
txtArguments.Text = Arguments
Else
End If
End If
End If
End Sub
End Class