C#代码将无法启动程序。 Win32Exception了未处理 [英] C# code won't launch programs. Win32Exception was unhandled

查看:962
本文介绍了C#代码将无法启动程序。 Win32Exception了未处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做一个启动一个按钮被点击时,一个程序的程序。这似乎为程序,如浏览器或Word,但不小的程序,如FRAPS工作,给我的错误




类型的未处理的异常System.ComponentModel.Win32Exception发生在System.dll中其他信息:系统找不到指定


文件

 私人无效Fraps_Click(对象发件人,EventArgs五)
{
的ProcessStartInfo的StartInfo =新的ProcessStartInfo();
startInfo.FileName =fraps.exe;
的Process.Start(StartInfo的);
}


解决方案

从的 MSDN




在启动过程之前,您必须至少设置FileName属性。文件名是任何应用程序或文件。文档定义为具有与其相关联的打开或默认操作任何类型的文件。您可以通过使用文件夹选项对话框,这是可以通过操作系统查看已注册的文件类型及其相关应用程序为您的计算机。高级按钮导致一个对话框,显示是否有与特定注册的文件类型关联的打开动作。




在你的情况fraps.exe是不相关的应用程序已注册的文件类型。所以给完整路径fraps.exe



中的代码示例会像以下(发现你的硬盘安装帧数和替换路径在第二行fraps.exe)

 的ProcessStartInfo的StartInfo =新的ProcessStartInfo(); 
startInfo.FileName = @C:\Program Files\fraps\fraps.exe //你的绝对路径
的Process.Start(StartInfo的);


I'm making a program that launches a program when a button is clicked. It seems to work for programs such as Chrome or Word but not smaller programs such as fraps and gives me the error

An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll Additional information: The system cannot find the file specified

private void Fraps_Click(object sender, EventArgs e)
{
    ProcessStartInfo startInfo = new ProcessStartInfo();
    startInfo.FileName = "fraps.exe";
    Process.Start(startInfo);
}

解决方案

Quoting from MSDN:

You must set at least the FileName property before you start the process. The file name is any application or document. A document is defined to be any file type that has an open or default action associated with it. You can view registered file types and their associated applications for your computer by using the Folder Options dialog box, which is available through the operating system. The Advanced button leads to a dialog box that shows whether there is an open action associated with a specific registered file type.

In your case fraps.exe is not a registered file type associated application. So give FULL PATH to fraps.exe

The Code Example would be like the following (Find fraps installation on your hdd and replace path to fraps.exe in second line)

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = @"C:\Program Files\fraps\fraps.exe"; // Your absolute PATH 
Process.Start(startInfo);

这篇关于C#代码将无法启动程序。 Win32Exception了未处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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