使用SHELLEXECUTEINFO。 [英] Working with SHELLEXECUTEINFO.

查看:367
本文介绍了使用SHELLEXECUTEINFO。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我正在尝试打开特定文件的属性对话框。我在互联网上找到了这个。给我一个错误 Windows无法找到'C'。确保正确输入名称,然后重试。

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.

#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)





谢谢

推荐答案

我怀疑你的字符串都是Unicode而不是ASCII,因此您应该使用 LPWStr 类型来编组字符串。
I suspect that your strings are all Unicode rather than ASCII so you should be using the LPWStr type for marshalling your strings.


这篇关于使用SHELLEXECUTEINFO。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆