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

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

问题描述

我需要让 .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.

.NETCore 2.0 Process.Start(string 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:Usersuser2DesktopXXXX.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.

我无法指定确切的 exe 文件路径作为方法的参数,因为用户的环境是不同的(包括 Windows 版本)并且不受我的控制.这也是为什么我需要将程序移植到 .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:Usersuser2DesktopXXXX.reg")

不要忘记/c

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

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