C# .NET 中的 ShellExecute 等效项

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/258416/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 20:15:16  来源:igfitidea点击:

ShellExecute equivalent in .NET

c#.netwinapiwindows-shellshellexecute

提问by Martin Kenny

I'm looking for the .NET-preferred way of performing the same type of thing that ShellExecute does in Win32 (opening, printing, etc. for arbitrary file types).

我正在寻找 .NET 首选的方式来执行 ShellExecute 在 Win32 中所做的相同类型的事情(打开、打印等任意文件类型)。

I've been programming Windows for over 20 years, but I'm a complete newbie at .NET, so maybe I'm just looking in the wrong places. I'm currently using .NET 2.0 (VS C# 2005), but could use VS 2008 if need be.

我已经为 Windows 编程了 20 多年,但我是 .NET 的完全新手,所以也许我只是找错了地方。我目前使用 .NET 2.0 (VS C# 2005),但如果需要,可以使用 VS 2008。

If the only answer is to use P/Invoke, then I might be better just writing my small utility using Win32 anyway.

如果唯一的答案是使用 P/Invoke,那么我最好还是使用 Win32 编写我的小实用程序。

采纳答案by Marc Gravell

Process.Start.

进程。开始。

Note that advanced uses (printing etc) require using a ProcessStartInfoand setting the Verbproperty.

请注意,高级用途(打印等)需要使用ProcessStartInfo并设置Verb属性。

回答by Corey Trager

System.Diagnostics.Process.Start.

System.Diagnostics.Process.Start。

I bet you had trouble finding it because it is in the System.Diagnostics namespace. "Diagnostics"? Usually with 20 years experience one thing you get good at is guessing at what something will be called in a new API/language, but this one tricked me.

我敢打赌你很难找到它,因为它在 System.Diagnostics 命名空间中。“诊断”?通常有 20 年的经验,你擅长的一件事就是猜测什么东西会在新的 API/语言中被调用,但这件事欺骗了我。

回答by Cyril Gupta

Did you try System.Diagnostics.Process.Start() function... It's more or less similar to ShellExecute. You can open exes, documents. I haven't checked printing yet, Marc has told you how already.

您是否尝试过 System.Diagnostics.Process.Start() 函数...它或多或少类似于 ShellExecute。你可以打开exe文件,文件。我还没有检查印刷,马克已经告诉你如何了。