| |
VB.NET - Ein- und UmsteigerZiel von Link (.lnk) file finden - Funktion liefert manchmal falsche Zielpfade | | | Autor: kmoney | Datum: 26.02.12 17:59 |
| Diese Funktion liefert Target Pfad einer Link Datei (.lnk).
Bei manchen funktioniert es korrekt bei anderen nicht. Z.b. wenn ich Skype Verknuepfung von meinem Desktop nehme kommt:
"C:\Windows\Installer\{...}\SkypeIcon.exe"
Gibt es dafuer einen Fix? (Scripting Host moechte ich deaktiviert lassen)
Reference: Shell32.dll
Public Shared Function GetLnkTarget(ByVal lnkPath As String) As String
Dim shl = New Shell32.Shell()
' Move this to class scope
lnkPath = System.IO.Path.GetFullPath(lnkPath)
Dim dir = shl.[NameSpace](System.IO.Path.GetDirectoryName(lnkPath))
Dim itm = dir.Items().Item(System.IO.Path.GetFileName(lnkPath))
Dim lnk = DirectCast(itm.GetLink, Shell32.ShellLinkObject)
Return lnk.Target.Path
End Function
Beitrag wurde zuletzt am 26.02.12 um 18:07:24 editiert. | |
Re: Ziel von Link (.lnk) file finden - Funktion liefert manchmal falsche Zielpfade | | | Autor: kmoney | Datum: 28.02.12 00:25 |
| Hi,
nein das ist nicht der korrekte Pfad!!!!!!!!!!!!
Oeffne ich das Skype Desktop Icon steht da:
"C:\Program Files (x86)\Skype\Skype.exe"
Weiss jemand wie man diesen Bug umgeht? | |
Re: Ziel von Link (.lnk) file finden - Funktion liefert manchmal falsche Zielpfade | | | Autor: kmoney | Datum: 28.02.12 15:10 |
| Cool, danke das hat funktioniert! Allerdings muss gesagt sein, dass man ersten mit der Shell Methode checken muss ob ein \WIndows\Installer\{ Pfad heraus kommt und dann die MSIParser Methode verwenden.
Hier ist die Klasse in VB:
Imports System.Collections.Generic
Imports System.Text
Imports System.Runtime.InteropServices
Imports Shell32
Module ParseLnk
Public Class MsiShortcutParser
'
' UINT MsiGetShortcutTarget(
' LPCTSTR szShortcutTarget,
' LPTSTR szProductCode,
' LPTSTR szFeatureId,
' LPTSTR szComponentCode
' );
'
<DllImport("msi.dll", CharSet:=CharSet.Auto)> _
Private Shared Function MsiGetShortcutTarget(ByVal targetFile As _
String, ByVal productCode As StringBuilder, ByVal featureID As _
StringBuilder, ByVal componentCode As StringBuilder) As Integer
End Function
Public Enum InstallState
NotUsed = -7
BadConfig = -6
Incomplete = -5
SourceAbsent = -4
MoreData = -3
InvalidArg = -2
Unknown = -1
Broken = 0
Advertised = 1
Removed = 1
Absent = 2
Local = 3
Source = 4
[Default] = 5
End Enum
Public Const MaxFeatureLength As Integer = 38
Public Const MaxGuidLength As Integer = 38
Public Const MaxPathLength As Integer = 1024
'
' INSTALLSTATE MsiGetComponentPath(
' LPCTSTR szProduct,
' LPCTSTR szComponent,
' LPTSTR lpPathBuf,
' DWORD* pcchBuf
' );
'
<DllImport("msi.dll", CharSet:=CharSet.Auto)> _
Private Shared Function MsiGetComponentPath(ByVal productCode As _
String, ByVal componentCode As String, ByVal componentPath As _
StringBuilder, ByRef componentPathBufferSize As Integer) As InstallState
End Function
Public Shared Function ParseShortcut(ByVal file As String) As String
Dim product As New StringBuilder(MaxGuidLength + 1)
Dim feature As New StringBuilder(MaxFeatureLength + 1)
Dim component As New StringBuilder(MaxGuidLength + 1)
MsiGetShortcutTarget(file, product, feature, component)
Dim pathLength As Integer = MaxPathLength
Dim path As New StringBuilder(pathLength)
Dim installState__1 As InstallState = MsiGetComponentPath( _
product.ToString(), component.ToString(), path, pathLength)
If installState__1 = InstallState.Local Then
Return path.ToString()
Else
Return Nothing
End If
End Function
Public Shared Function ParseShortcutShellOld(ByVal lnkPath As String) _
As String
Dim shl = New Shell32.Shell()
' Move this to class scope
lnkPath = System.IO.Path.GetFullPath(lnkPath)
Dim dir = shl.[NameSpace](System.IO.Path.GetDirectoryName(lnkPath))
Dim itm = dir.Items().Item(System.IO.Path.GetFileName(lnkPath))
Dim lnk = DirectCast(itm.GetLink, Shell32.ShellLinkObject)
'Dim lnk As Shell32.ShellLinkObject = CType(itm.GetLink,
' Shell32.ShellLinkObject)
Return lnk.Target.Path
End Function
Public Shared Function ParseShortcutShell(ByVal shortcutFilename As _
String) As String
Dim pathOnly As String = System.IO.Path.GetDirectoryName( _
shortcutFilename)
Dim filenameOnly As String = System.IO.Path.GetFileName( _
shortcutFilename)
Dim shell As New Shell()
Dim folder As Folder = shell.[NameSpace](pathOnly)
Dim folderItem As FolderItem = folder.ParseName(filenameOnly)
If folderItem IsNot Nothing Then
Dim link As Shell32.ShellLinkObject = DirectCast( _
folderItem.GetLink, Shell32.ShellLinkObject)
'Dim lnk As Shell32.ShellLinkObject = CType(itm.GetLink,
' Shell32.ShellLinkObject)
Return link.Path
Else
MsgBox("Error retrieving application path from shortcut", _
vbCritical)
Return ""
End If
End Function
End Class
End Module | |
Re: Ziel von Link (.lnk) file finden - Funktion liefert manchmal falsche Zielpfade | | | Autor: Toolmaster | Datum: 14.06.12 09:06 |
| Hallo Leute,
sorry das ich dieses doch etwas altere Thema noch einmal ausgrabe. Aber es giebt verknüpfungen die ich auch mit dieses Methode nicht lesen kann. ZB. in Windows 7 im Startmenü die (Windows-Fax und -Scan.lnk) kann mit beiden methoden nicht ausgelesen werden.
Kann mir da noch wer helfen.
Grüße Georg | |
Re: Ziel von Link (.lnk) file finden - Funktion liefert manchmal falsche Zielpfade | | | Autor: Toolmaster | Datum: 18.08.12 07:17 |
| Nochmal eine frage hierzu.
Bei manchen office 2010 Verknüpfungen kommt InvalidArg = -2 zum greifen.
Wie kann man das umgehen.
Grüße georg | |
| Sie sind nicht angemeldet! Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.
Einloggen | Neu registrieren |
|
|
sevZIP40 Pro DLL
Zippen und Unzippen wie die Profis!
Mit nur wenigen Zeilen Code statten Sie Ihre Anwendungen ab sofort mit schnellen Zip- und Unzip-Funktionen aus. Hierbei lassen sich entweder einzelnen Dateien oder auch gesamte Ordner zippen bzw. entpacken. Weitere InfosTipp des Monats TOP Entwickler-Paket
TOP-Preis!!
Mit der Developer CD erhalten Sie insgesamt 24 Entwickler- komponenten und Windows-DLLs. Die Einzelkomponenten haben einen Gesamtwert von 1605.50 EUR...
Jetzt nur 599,00 EURWeitere Infos
|
|
|
Copyright ©2000-2024 vb@rchiv Dieter Otter Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.
Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel
|
|