.Net Core 2.0 Process.Start抛出“指定的可执行文件不是此OS平台的有效应用程序”。 [英] .Net Core 2.0 Process.Start throws "The specified executable is not a valid application for this OS platform"

查看:672
本文介绍了.Net Core 2.0 Process.Start抛出“指定的可执行文件不是此OS平台的有效应用程序”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要让.reg文件和.msi文件使用这两个文件类型在用户Windows上关联的任何可执行文件自动执行。

I need to let a .reg file and a .msi file execute automatically using whatever executables these two file types associated with on user's Windows.

。NET Core 2.0 Process.Start(字符串fileName)docs 说:
该文件名不需要表示可执行文件。它可以是扩展名已与系统上安装的应用程序相关联的任何文件类型。

.NET Core 2.0 Process.Start(string fileName) docs says: "the file name does not need to represent an executable file. It can be of any file type for which the extension has been associated with an application installed on the system."

但是

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)

中具有ErrorCode和HResult -2147467259和NativeErrorCode 193。

with ErrorCode and HResult -2147467259, and NativeErrorCode 193.

相同的代码在.Net Framework 3.5或4控制台应用程序中也有效。

The same code did work in .Net Framework 3.5 or 4 console app.

我可以由于用户的环境是多种多样的(包括Windows版本)并且不受我的控制,因此请指定确切的exe文件路径作为方法的参数。这也是为什么我需要将该程序移植到.Net Core的原因,试图使其作为 SCD 控制台应用程序,因此不需要安装特定的.Net Framework或.NET Core版本。

I can't specify exact exe file paths as the method's parameter since users' environments are variant (including Windows versions) and out of my control. That's also why I need to port the program to .Net Core, trying to make it work as SCD console app so that installation of specific .Net Framework or .NET Core version is not required.

例外在Visual Studio调试运行中以及作为win-x86 SCD发布时都会抛出该错误。我的PC是Win7 64位,并且我确定.reg和.msi与常规Windows PC一样与常规程序相关联。

The exception is thrown both in Visual Studio debugging run and when published as win-x86 SCD. My PC is Win7 64bit and I'm sure .reg and .msi are associated with regular programs as usual Windows PC does.

有解决方案吗?感谢您的帮助。

Is there solution for this? Any help is appreciated.

推荐答案

您必须执行cmd.exe

You have to execute cmd.exe

var proc = Process.Start(@"cmd.exe ",@"/c C:\Users\user2\Desktop\XXXX.reg")

不要忘记/ c

这篇关于.Net Core 2.0 Process.Start抛出“指定的可执行文件不是此OS平台的有效应用程序”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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