壳牌VS的Process.Start执行外部应用程序 [英] Shell Vs Process.start for executing external application
问题描述
我可以从我的应用程序在以下方式打开Windows计算器:
-
使用
壳牌()
壳牌(C:\ WINDOWS \ SYSTEM32 \的calc.exe)
-
使用
的Process.Start()
的Process.Start(C:\ WINDOWS \ SYSTEM32 \的calc.exe)
-
打开记事本应用程序
壳牌(C:\ WINDOWS \ SYSTEM32 \ NOTEPAD.EXE,AppWinStyle.NormalFocus) 的Process.Start(C:\ WINDOWS \ SYSTEM32 \ NOTEPAD.EXE,AppWinStyle.NormalFocus)
谁能告诉我,什么是这两个电话之间的区别是什么?哪一个是最好的做法?
在两个例子中基本上没有差别,但
的Process.Start
是preferred,因为它可以让你在控制过程中更多的选择。您可以使用指定更多的选项的ProcessStartInfo 对象作为参数。</ P>
壳牌
只返回进程ID,你将不得不寻找在运行,而的Process.Start $ C $进程列表C>返回
进程
的对象,你可以用它来检查其状态等。
另外请注意,壳牌
驻留在 Microsoft.VisualBasic程序
命名其中的主要的含德precated遗留的目的的方法。你应该尽量避免在有利于在另一个命名空间的替代使用任何在这里了。
I can open the windows calculator from my application in following ways:
Using
Shell()
Shell("C:\WINDOWS\system32\calc.exe")
Using
Process.start()
Process.start("C:\WINDOWS\system32\calc.exe")
Open notepad application
Shell("C:\WINDOWS\system32\notepad.exe", AppWinStyle.NormalFocus) Process.start("C:\WINDOWS\system32\notepad.exe", AppWinStyle.NormalFocus)
Can anyone tell me that what is the difference between these two calls? which one is the best practice?
In the two examples there is essentially no difference but
Process.Start
is preferred because it gives you more options on controlling the process. You can specify much more options using a ProcessStartInfo object as a parameter.
Shell
only returns the process id which you would have to look up in the list of running processes whereas Process.Start
return a Process
object which you can use to check for its state etc.
Also note that Shell
resides in the Microsoft.VisualBasic
namespace which largely contains deprecated methods for legacy purposes. You should try to avoid using anything in here in favour of an alternative in another namespace.
这篇关于壳牌VS的Process.Start执行外部应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!