Visual Basic shell32.shell

1

For more than likely a very obvious reason when I try build or run my program it breaks on this function below:

Public Function GetLnkTarget(lnkPath As String) As String
    Dim shl = New Shell32.Shell()
    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)

    Try
        Return lnk.Target.Path
    Catch ex As Exception
        Return Nothing
    End Try
End Function

The error I get is:

System.InvalidCastException
HResult=0x80004002
Message=Unable to cast COM object of type 'System.__ComObject' to interface type 'Shell32.Shell'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{286E6F1B-7113-4355-9562-96B7E9D64C54}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
Source=Administrator Tools

Any feedback/ideas on how I can proceed with this would be great!

vb.net
shell32
asked on Stack Overflow Dec 13, 2018 by S. Cuth • edited Dec 13, 2018 by Blackwood

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0