因為某些原因需要自動啟動一個 Winform 程序,可能是因為第三方資源的原因,使用 System.Diagnostics.Process 無法成功啟動 (可以看到界面,但是會報 Unhandled Exception)
解決方案 (使用 Shell32)
導入方法
[DllImport("shell32.dll")]
public static extern int ShellExecute(IntPtr hwnd, StringBuilder lpszOp, StringBuilder lpszFile, StringBuilder lpszParams, StringBuilder lpszDir, int FsShowCmd);
調用
ShellExecute(IntPtr.Zero, new StringBuilder("Open"), new StringBuilder("可執行文件名"), new StringBuilder(""), new StringBuilder("文件所在目錄"), 1);
參考