我需要让一个.reg文件和一个.msi文件在用户的Windows上自动执行,使用与这两种文件类型相关联的任何可执行文件。
.NET Core 2.0 Process.Start(string fileName)文档说:
“文件名不需要代表一个可执行文件。它可以是任何已经与系统上安装的应用程序关联的文件类型。”
然而,
然而,
using(var proc = Process.Start(@"C:\Users\user2\Desktop\XXXX.reg")) { } //.msi also
给我
System.ComponentModel.Win32Exception (0x80004005): The specified executable is not a valid application for this OS platform.
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start(String fileName)
使用错误代码和HResult为-2147467259,以及本机错误代码193。
相同的代码在.NET Framework 3.5或4控制台应用程序中工作。
我无法指定确切的exe文件路径作为方法的参数,因为用户的环境是不同的(包括Windows版本),并且超出了我的控制范围。这也是为什么我需要将程序移植到.NET Core,尝试将其作为SCD控制台应用程序运行,以便不需要安装特定的.NET Framework或.NET Core版本。
异常在Visual Studio调试运行和发布为win-x86 SCD时都会抛出。我的PC是Win7 64位,我确定.reg和.msi与常规程序一样关联。
是否有解决方案?感谢任何帮助。
UseShellExecute
从false
更改为true
对我有用 :-) - Greg TrevellickSystem.Diagnostics.Process.Start("rundll32.exe", "shell32.dll, OpenAs_RunDLL " + item.FileName);
- Wolfgang Schorge