【问题标题】:.NET WPF Process.Start() not working on Vista and Windows 7.NET WPF Process.Start() 在 Vista 和 Windows 7 上不起作用
【发布时间】:2010-10-25 18:26:51
【问题描述】:

我有 WPF 应用程序。 在 Windows7 上测试我的应用后,发现打开帮助不起作用。

基本上是打开我调用的chm帮助文件:

Process.Start("help.chm");

然后什么也没有发生。我还在 Vista SP1 上尝试了我的应用程序,结果相同。 我是两个操作系统的管理员

我已经用谷歌搜索过这个问题,但没有找到解决方案。

有没有办法解决这个问题?

您是否遇到过这种类型的不兼容问题。

谢谢!

【问题讨论】:

    标签: c# .net wpf windows-7 windows-vista


    【解决方案1】:

    你试过 ShellExecute 吗?

    使用 System.Runtime.InteropServices;

    [DllImport("shell32.dll", CharSet = CharSet.Auto)] static extern bool ShellExecuteEx(ref SHELLEXECUTEINFO lpExecInfo);

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
    public struct SHELLEXECUTEINFO
    {
        public int cbSize;
        public uint fMask;
        public IntPtr hwnd;
        [MarshalAs(UnmanagedType.LPTStr)]
        public string lpVerb;
        [MarshalAs(UnmanagedType.LPTStr)]
        public string lpFile;
        [MarshalAs(UnmanagedType.LPTStr)]
        public string lpParameters;
        [MarshalAs(UnmanagedType.LPTStr)]
        public string lpDirectory;
        public int nShow;
        public IntPtr hInstApp;
        public IntPtr lpIDList;
        [MarshalAs(UnmanagedType.LPTStr)]
        public string lpClass;
        public IntPtr hkeyClass;
        public uint dwHotKey;
        public IntPtr hIcon;
        public IntPtr hProcess;
    }
    

    您可以尝试使用以下命令开始流程:

            SHELLEXECUTEINFO info = new SHELLEXECUTEINFO();
            info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(info);
            info.lpVerb = "open";
            info.lpFile = "help.chm";
            info.nShow = 5;
            info.fMask = 12;
    
            ShellExecuteEx(ref info);
    

    (http://www.pinvoke.net/default.aspx/shell32.ShellExecuteEx)

    【讨论】:

    • 直接调用 ShellExecute 和使用 UseShellExecute=true 调用 ProcessStart(ProcessStartInfo) 有什么区别?
    【解决方案2】:

    这个SO thread 应该可以帮助你。另外,这里有一个关于 UAC 的 pretty detailed article 以及如何提升。

    【讨论】:

      【解决方案3】:

      它只是 .chm 文件吗?如果是这样,它可能无法打开,因为默认情况下,不受信任位置的 chm 文件被阻止。请参阅:KB902225。从this article 看来,您可以通过编程方式解除对它们的阻止,即使它只是首先启动 Sysinternals streams.exe(如文章中所引用)。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-24
        • 1970-01-01
        相关资源
        最近更新 更多