Jonathan Jenne 16ac706a6e WIP
2019-08-05 16:32:47 +02:00

62 lines
2.1 KiB
VB.net

Imports System.Runtime.InteropServices
Imports DigitalData.Modules.Logging
Public Class ClassWindowsAPI
Private Const SEE_MASK_INVOKEIDLIST = &HC
Private Const SEE_MASK_NOCLOSEPROCESS = &H40
Private Const SEE_MASK_FLAG_NO_UI = &H400
Private Const SW_SHOW As Short = 5
Private _LogConfig As LogConfig
Private _Logger As Logger
<DllImport("Shell32", CharSet:=CharSet.Auto, SetLastError:=True)>
Public Shared Function ShellExecuteEx(ByRef lpExecInfo As ShellExecuteInfo) As Boolean
End Function
Public Structure ShellExecuteInfo
Public cbSize As Integer
Public fMask As Integer
Public hwnd As IntPtr
<MarshalAs(UnmanagedType.LPTStr)> Public lpVerb As String
<MarshalAs(UnmanagedType.LPTStr)> Public lpFile As String
<MarshalAs(UnmanagedType.LPTStr)> Public lpParameters As String
<MarshalAs(UnmanagedType.LPTStr)> Public lpDirectory As String
Dim nShow As Integer
Dim hInstApp As IntPtr
Dim lpIDList As IntPtr
<MarshalAs(UnmanagedType.LPTStr)> Public lpClass As String
Public hkeyClass As IntPtr
Public dwHotKey As Integer
Public hIcon As IntPtr
Public hProcess As IntPtr
End Structure
Public Sub New(LogConfig As LogConfig)
_LogConfig = LogConfig
_Logger = LogConfig.GetLogger()
End Sub
Public Sub ShowFileProperties(FilePath As String)
If FilePath = String.Empty OrElse Not IO.File.Exists(FilePath) Then
Logger.Warn("Could not show file properties. FilePath '{0}' is invalid or does not exist.", FilePath)
Exit Sub
End If
Dim oInfo As New ShellExecuteInfo With {
.cbSize = Marshal.SizeOf(oInfo),
.lpVerb = "properties",
.lpFile = FilePath,
.nShow = SW_SHOW,
.fMask = SEE_MASK_INVOKEIDLIST
}
If Not ShellExecuteEx(oInfo) Then
Dim ex As New ComponentModel.Win32Exception(Marshal.GetLastWin32Error())
Logger.Warn("Could not show file properties. Reason: {0}", ex.Message)
Logger.Error(ex)
End If
End Sub
End Class