如何启动Windows“运行” C#对话框 [英] How to start windows "run" dialog from C#

查看:134
本文介绍了如何启动Windows“运行” C#对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从C#代码中的Windows启动运行对话框(Windows + R)。



我认为这可以使用explorer.exe完成,不清楚如何。

解决方案

不支持 RunFileDlg 被微软从未来版本的Windows中删除(我将授予MS对后向兼容性的承诺,而且这个API虽然没有文档,似乎是相当广为人知的,但这仍然是一种可能性)。 >

启动运行对话框的支持方式是使用 IShellDispatch :: FileRun 方法。



在C#中,你可以通过访问Add Reference,选择COM选项卡并选择Microsoft Shell Controls and Automation来访问此方法。执行此操作后,您可以按如下所示启动对话框:

  Shell32.Shell shell = new Shell32.Shell(); 
shell.FileRun();

是的,$ code> RunFileDlg API提供更多的可定制性,但这样做的优势在于文件化,支持性,因此在将来不太可能破裂。


I want to start the run dialog (Windows+R) from Windows within my C# code.

I assume this can be done using explorer.exe but I'm not sure how.

解决方案

The RunFileDlg API is unsupported and may be removed by Microsoft from future versions of Windows (I'll grant that MS's commitment to backwards compatibility and the fact that this API, though undocumented, appears to be fairly widely known makes this unlikely, but it's still a possibility).

The supported way to launch the run dialog is using the IShellDispatch::FileRun method.

In C#, you can access this method by going to Add Reference, select the COM tab, and select "Microsoft Shell Controls and Automation". After doing this you can launch the dialog as follows:

Shell32.Shell shell = new Shell32.Shell();
shell.FileRun();

Yes, the RunFileDlg API offers more customizability, but this has the advantage of being documented, supported, and therefore unlikely to break in the future.

这篇关于如何启动Windows“运行” C#对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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