Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Greetings from Germany
and sorry for my clumsy english

I Need to open the file-propertie dialogue as normally provided by Windows. It would be quite a lot of code to build it from scratch on my own - and some (quite some) years ago - with VB6 - it was quite simply to call it via shellexecuteex and shellexuteinfo.

I searched the net and found some snipplets which should do the Job in vb.net (see code below) But: it does not work. It doesn't even produce an errormessage. It does just...... nothing. (To be precise if i Switch Project Settings for compolation to X86 it does produce an error message when shellexecuteex is called in the last line) But when i leave to x64 (as i want) it just does: nothing.

What am i doing wrong ?
What is wrong with the code ?
Or is there another way to do the Job ?

Thanks a lot for any hint

Michael

And here is the code:

XML
imports System.Runtime.InteropServices

Module Properties

    Public Structure SHELLEXECUTEINFO
        Public cbSize As IntPtr?
        Public fMask As IntPtr
        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 IntPtr
        Public hIcon As IntPtr
        Public hProcess As IntPtr
    End Structure

    Private Const SEE_MASK_FLAG_NO_UI = &H400
    Private Const SEE_MASK_INVOKEIDLIST = &HC
    Private Const SEE_MASK_NOCLOSEPROCESS = &H40
    Private Const SW_SHOW As Integer = 5
    'Dekclarationen zum Anzeigen der Dateieigenschaften
    Private Declare Function ShellExecuteEx Lib "shell32.dll" (LPSHELLEXECUTEINFO As SHELLEXECUTEINFO) As Long

    Public Sub ShowProperties(ByVal path As String)
        Dim fi As New IO.FileInfo(path)
        Dim info As New SHELLEXECUTEINFO()
        info.cbSize = CType(Marshal.SizeOf(info), IntPtr)
        info.lpVerb = "properties"
        info.lpFile = fi.Name
        info.lpDirectory = fi.DirectoryName
        info.nShow = CType(SW_SHOW, IntPtr)
        info.fMask = CType(SEE_MASK_INVOKEIDLIST, IntPtr)
        ShellExecuteEx(info)
    End Sub

End Module
Posted
Updated 27-May-15 7:19am
v3

1 solution

Below you will see that i have made a few changes to your code.

Imports System.Runtime.InteropServices

Module PropertiesDialog

    Public Structure SHELLEXECUTEINFO
        Public cbSize As IntPtr
        Public fMask As IntPtr
        Public hwnd As IntPtr
        Public lpVerb As String 'Removed MarshalAs
        Public lpFile As String 'Removed MarshalAs
        Public lpParameters As String 'Removed MarshalAs
        Public lpDirectory As String 'Removed MarshalAs
        Dim nShow As Integer
        Dim hInstApp As IntPtr
        Dim lpIDList As IntPtr
        Public lpClass As String 'Removed MarshalAs
        Public hkeyClass As IntPtr
        Public dwHotKey As IntPtr
        Public hIcon As IntPtr
        Public hProcess As IntPtr
    End Structure

    Private Const SEE_MASK_FLAG_NO_UI = &H400
    Private Const SEE_MASK_INVOKEIDLIST = &HC
    Private Const SEE_MASK_NOCLOSEPROCESS = &H40
    Private Const SW_SHOW As Integer = 5
    'Dekclarationen zum Anzeigen der Dateieigenschaften
    Private Declare Function ShellExecuteEx Lib "shell32.dll" (ByRef LPSHELLEXECUTEINFO As SHELLEXECUTEINFO) As Long 'Added ByRef

    Sub ShowProperties(ByVal path As String)
        Dim fi As New IO.FileInfo(path)
        Dim info As New SHELLEXECUTEINFO()
        info.cbSize = CType(Marshal.SizeOf(info), IntPtr)
        info.lpVerb = "properties"
        info.lpFile = fi.Name
        info.lpDirectory = fi.DirectoryName
        info.nShow = CType(SW_SHOW, IntPtr)
        info.fMask = CType(SEE_MASK_INVOKEIDLIST, IntPtr)
        ShellExecuteEx(info)
    End Sub

End Module
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900