Překvapivě ne, i když jsem očekával stejnou chybu. Přikládám kód, pokud chcete vyzkoušet:
Public Function GetShortcutInfo(path_ As String) As FileType
If (Not String.IsNullOrEmpty(path_)) And (Path.GetExtension(path_).ToUpper = ".LNK") Then
Try
Dim shell As New IWshRuntimeLibrary.WshShell
Dim link As IWshRuntimeLibrary.IWshShortcut = CType(shell.CreateShortcut(path_), IWshRuntimeLibrary.IWshShortcut)
Dim fileType_ As New FileType
fileType_.Path = link.TargetPath
fileType_.Arguments = link.Arguments
fileType_.Description = Path.GetFileNameWithoutExtension(link.FullName)
fileType_.IconPath = link.IconLocation.Substring(0, link.IconLocation.LastIndexOf(","))
fileType_.IconIndex = Convert.ToInt32(link.IconLocation.Substring(link.IconLocation.LastIndexOf(",") + 1))
Return fileType_
Catch ex As Exception
Return New FileType
End Try
Else
Return New FileType
End If
End Function
funkce vrací instanci této třídy:
Public Class FileType
Private path_ As String
Private description_ As String
Private arguments_ As String
Private iconPath_ As String
Private iconIndex_ As Integer
Public Property Path() As String
Get
Return path_
End Get
Set(ByVal value As String)
path_ = value
End Set
End Property
Public Property Description() As String
Get
Return description_
End Get
Set(ByVal value As String)
description_ = value
End Set
End Property
Public Property Arguments() As String
Get
Return arguments_
End Get
Set(ByVal value As String)
arguments_ = value
End Set
End Property
Public Property IconIndex() As Integer
Get
Return iconIndex_
End Get
Set(ByVal value As Integer)
iconIndex_ = value
End Set
End Property
Public Property IconPath() As String
Get
Return iconPath_
End Get
Set(ByVal value As String)
iconPath_ = value
End Set
End Property
Public Sub New()
path_ = String.Empty
description_ = String.Empty
arguments_ = String.Empty
iconPath_ = String.Empty
iconIndex_ = 0
End Sub
End Class
|