mario.deghetto

Visual Basic & .NET
posts - 332, comments - 79, trackbacks - 0

#11 Leggere il nome del file in uno “Shortcut” (file .LNK)

In un nuovo progetto, aggiungere il riferimento alla libreria COM (unmanaged) “Windows Script Host Object Model“.

Nella sezione del codice del form (Form1.vb) inserire questo esempio:

  Public Class Form1     Private Sub Button1_Click(ByVal sender As System.Object, _           ByVal e As System.EventArgs) Handles Button1.Click         MessageBox.Show(ReadShortcut("C:\prova2.lnk"))     End Sub     Public Function ReadShortcut(ByVal FilePath As String) As String         If System.IO.File.Exists(FilePath) Then             Dim theShell As New IWshRuntimeLibrary.WshShell()             Dim theShortcut As IWshRuntimeLibrary.WshShortcut = _                    theShell.CreateShortcut(FilePath)             Return theShortcut.TargetPath         Else             Return "Il file non esiste."         End If     End Function
  End Class

Print | posted on mercoledì 14 ottobre 2009 4.46 |

Feedback

No comments posted yet.

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 5 and 8 and type the answer here:

Powered by: