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.
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:
Yes, the
RunFileDlg
API offers more customizability, but this has the advantage of being documented, supported, and therefore unlikely to break in the future.Another method would be to emulate the Windows+R key combination.
and call:
Use RunFileDlg:
Possible values for
flags
:See also How to programmatically open Run c++?