Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I'm trying to open the properties dialog of a particular file. I have found this in the internet. Giving me an error Windows cannot find 'C'. Make sure you typed the name correctly, and then try again.
VB
#Region "Shell Execute"
    <Runtime.InteropServices.DllImport("shell32.dll")> _
    Public Function ShellExecuteEx(ByRef lpExecInfo As SHELLEXECUTEINFO) As Boolean
    End Function

    Public Const SW_SHOW As Integer = 5
    Public Const SEE_MASK_INVOKEIDLIST As UInteger = &HC
    Public Const SEE_MASK_NOCLOSEPROCESS As UInteger = &H40
    Public Const SEE_MASK_FLAG_NO_UI As UInteger = &H400

    <Runtime.InteropServices.StructLayout(Runtime.InteropServices.LayoutKind.Sequential)> _
    Public Structure SHELLEXECUTEINFO
        Public cbSize As Integer
        Public fMask As Integer
        Public hwnd As IntPtr
        <Runtime.InteropServices.MarshalAs(Runtime.InteropServices.UnmanagedType.LPTStr)> Public lpVerb As String
        <Runtime.InteropServices.MarshalAs(Runtime.InteropServices.UnmanagedType.LPTStr)> Public lpFile As String
        <Runtime.InteropServices.MarshalAs(Runtime.InteropServices.UnmanagedType.LPTStr)> Public lpParameters As String
        <Runtime.InteropServices.MarshalAs(Runtime.InteropServices.UnmanagedType.LPTStr)> Public lpDirectory As String
        Dim nShow As Integer
        Dim hInstApp As IntPtr
        Dim lpIDList As IntPtr
        <Runtime.InteropServices.MarshalAs(Runtime.InteropServices.UnmanagedType.LPTStr)> Public lpClass As String
        Public hkeyClass As IntPtr
        Public dwHotKey As Integer
        Public hIcon As IntPtr
        Public hProcess As IntPtr
    End Structure
#End Region

Dim fi As New IO.FileInfo("C:\InstallHistory.log")
'Code for opening the file properties
Dim info As New SHELLEXECUTEINFO()
info.cbSize = Runtime.InteropServices.Marshal.SizeOf(info)
info.fMask = SEE_MASK_NOCLOSEPROCESS
info.hwnd = Nothing
info.lpVerb = Nothing
info.lpFile = fi.FullName
info.lpParameters = ""
info.lpDirectory = Nothing
info.nShow = SW_SHOW
info.hInstApp = Nothing
ShellExecuteEx(info)

'I have tried this also but same error
info.cbSize = Runtime.InteropServices.Marshal.SizeOf(info)
info.lpVerb = "properties"
info.lpFile = fi.Name
info.lpDirectory = fi.DirectoryName
info.nShow = SW_SHOW
info.fMask = SEE_MASK_INVOKEIDLIST
ShellExecuteEx(info)


Thanks
Posted
Updated 5-Jan-15 3:45am
v2

1 solution

I suspect that your strings are all Unicode rather than ASCII so you should be using the LPWStr type for marshalling your strings.
 
Share this answer
 
Comments
hansoctantan 7-Jan-15 5:44am    
same error
Richard MacCutchan 7-Jan-15 6:42am    
Try changing your definition to :
Public Function ShellExecuteExW(ByRef lpExecInfo As SHELLEXECUTEINFO) As Boolean
hansoctantan 9-Jan-15 5:30am    
thanks, it works

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