.NET WPF Process.Start() not working on Vista and Windows 7

两盒软妹~` 提交于 2019-12-08 07:55:12

问题


I have WPF application. After testing my app on Windows7 and realized that opening help does not work.

Basically to open chm help file I call:

Process.Start("help.chm");

And nothing happens. I have also tried my app on Vista SP1, same result. I'm admin in both OS'es

I have googled this problem, but have not found solution to it.

Is there way to solve this problem?

Have you experienced this types of incompatibilities.

Thank You!


回答1:


have you tried ShellExecute ?

using 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;
}

and you can try to start process with :

        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)




回答2:


This SO thread should help you. Also, here's a pretty detailed article on UAC and how to elevate.




回答3:


Is it just .chm files? If so it may not be opening because, by default, chm files in untrusted locations are blocked. See: KB902225. From this article it appears that you may be able to unblock them programmatically, even if it's just by launching Sysinternals streams.exe first (as referenced in the article).



来源:https://stackoverflow.com/questions/856236/net-wpf-process-start-not-working-on-vista-and-windows-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!