diff --git a/Windows/File.vb b/Windows/File.vb new file mode 100644 index 00000000..4f003e76 --- /dev/null +++ b/Windows/File.vb @@ -0,0 +1,36 @@ +Imports System.ComponentModel +Imports System.Runtime.InteropServices +Imports DigitalData.Modules.Logging +Imports DigitalData.Modules.Windows.NativeMethods + +Public Class File + Private _LogConfig As LogConfig + Private _Logger As Logger + + Public Sub New(LogConfig As LogConfig) + _LogConfig = LogConfig + _Logger = LogConfig.GetLogger() + End Sub + + Public Function OpenFileProperties(FilePath As String) As Boolean + Try + Dim oShellExecuteInfo As New ShellExecuteInfo() + oShellExecuteInfo.cbSize = Marshal.SizeOf(oShellExecuteInfo) + oShellExecuteInfo.lpVerb = "properties" + oShellExecuteInfo.lpFile = FilePath + oShellExecuteInfo.nShow = SW_SHOW + oShellExecuteInfo.fMask = SEE_MASK_INVOKEIDLIST + + If Not ShellExecuteEx(oShellExecuteInfo) Then + Dim oWin32Error = Marshal.GetLastWin32Error() + Dim oException As New Win32Exception(oWin32Error) + Throw oException + End If + + Return True + Catch ex As Exception + _Logger.Error(ex) + Return False + End Try + End Function +End Class diff --git a/Windows/NativeMethods.vb b/Windows/NativeMethods.vb index 443cb9fd..d5c328e9 100644 --- a/Windows/NativeMethods.vb +++ b/Windows/NativeMethods.vb @@ -5,6 +5,9 @@ Public Class NativeMethods Public Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" (ByVal hwnd As Int32) As Integer Public Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hWnd As IntPtr, ByVal WinTitle As String, ByVal MaxLength As Integer) As Integer + + Public Shared Function ShellExecuteEx(ByRef lpExecInfo As ShellExecuteInfo) As Boolean + End Function Public Shared Function GetDC(ByVal hwnd As IntPtr) As IntPtr End Function @@ -97,6 +100,10 @@ Public Class NativeMethods Public Const MEM_MAPPED As Integer = &H40000 Public Const MEM_TOP_DOWN As Integer = &H100000 Public Const INVALID_HANDLE_VALUE As Integer = -1 + Public Const SW_SHOW As Short = 5 + Public Const SEE_MASK_INVOKEIDLIST = &HC + Public Const SEE_MASK_NOCLOSEPROCESS = &H40 + Public Const SEE_MASK_FLAG_NO_UI = &H400 Public Enum PageProtection As UInteger NoAccess = &H1 @@ -130,6 +137,24 @@ Public Class NativeMethods End Function End Structure + Public Structure ShellExecuteInfo + Public cbSize As Integer + Public fMask As Integer + Public hwnd As IntPtr + Public lpVerb As String + Public lpFile As String + Public lpParameters As String + Public lpDirectory As String + Dim nShow As Integer + Dim hInstApp As IntPtr + Dim lpIDList As IntPtr + Public lpClass As String + Public hkeyClass As IntPtr + Public dwHotKey As Integer + Public hIcon As IntPtr + Public hProcess As IntPtr + End Structure + Public Structure PointAPI Public X As Integer diff --git a/Windows/Windows.vbproj b/Windows/Windows.vbproj index 6e1419a4..3bd354be 100644 --- a/Windows/Windows.vbproj +++ b/Windows/Windows.vbproj @@ -75,6 +75,7 @@ +