vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
Zippen wie die Profis!  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2025
 
zurück

 Sie sind aktuell nicht angemeldet.Funktionen: Einloggen  |  Neu registrieren  |  Suchen

VB.NET - Ein- und Umsteiger
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
alle Nachrichten anzeigenGesamtübersicht  |  Zum Thema  |  Suchen

 ThemaViews  AutorDatum
Ziel von Link (.lnk) file finden - Funktion liefert manchmal...8.427kmoney26.02.12 17:59
Re: Ziel von Link (.lnk) file finden - Funktion liefert manc...7.542ModeratorDaveS27.02.12 10:08
Re: Ziel von Link (.lnk) file finden - Funktion liefert manc...7.484kmoney28.02.12 00:25
Re: Ziel von Link (.lnk) file finden - Funktion liefert manc...7.616ModeratorDaveS28.02.12 10:46
Re: Ziel von Link (.lnk) file finden - Funktion liefert manc...7.775kmoney28.02.12 15:10
Re: Ziel von Link (.lnk) file finden - Funktion liefert manc...7.425Toolmaster18.08.12 07:17
Re: Ziel von Link (.lnk) file finden - Funktion liefert manc...7.460Toolmaster14.06.12 09:06

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

Funktionen:  Zum Thema  |  GesamtübersichtSuchen 

nach obenzurück
 
   

Copyright ©2000-2025 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