How to open the Run window programmatically
Asked Answered
D

5

5

Everyone knows the Run window that you can open with the shortcut Windows+R or directly in the Windows menu then Run.
I'm wondering how to open this Run window programmatically.
This window seems to be part of explorer.exe.
Does anyone have an idea on it ?

Diaphragm answered 12/10, 2011 at 8:59 Comment(2)
Why would you want to open the Run window? Can't you execute the programs directly instead of going trough the run command? or am i missing something here? I did try to locate if it were in a separate .exe or something like that, but as you say it seems to be a part of explorer.exe. Have you considered using cmd.exe?Grieve
First of all, re-read the question; they never said anything about running anything, they simply asked about programmatically opening the Run dialog. Second, the Run dialog has options (check-boxes) to alter how the program/file is run that may not be easy, if at all possible to accomplish using whatever language they are using.Supernormal
T
4

You can use IShellDispatch::FileRun to achieve this.

See Using the Windows RunFile dialog - The documented and undocumented way for details and sample code.

Takahashi answered 12/10, 2011 at 10:5 Comment(0)
X
2

FYI, in Windows 10/11 (havn't checked 8.x) you can open the Run dialog easily by calling:

explorer shell:::{2559a1f3-21d7-11d4-bdaf-00c04f60b9f0}

E.g. in a batch script:

start explorer shell:::{2559a1f3-21d7-11d4-bdaf-00c04f60b9f0}

... and in pwsh with quotes:

explorer "shell:::{2559a1f3-21d7-11d4-bdaf-00c04f60b9f0}"
Xerosis answered 30/6, 2023 at 13:37 Comment(2)
This works if run from cmd.exe, but if I run from PowerShell, it opens Explorer with my 'Documents' folder focused.Blackfish
@Blackfish You are right, that's really weird. But the following command also works in PowerShell - the quotes are crucial! explorer "shell:::{2559a1f3-21d7-11d4-bdaf-00c04f60b9f0}"Xerosis
T
1

If you mean that it could open say at 8:00 am, then you can use autohotkey and simply write SendInput {Raw}{Lwin}{R} and then compile it as an .exe and put it as a cron job

Telencephalon answered 12/10, 2011 at 10:11 Comment(2)
And what if the Win key combos are disabled?Supernormal
Not least of which, autohotkey introduces a whole slew of other issues, including security vulnerabilitiesGalvani
B
0

In PowerShell:

(New-Object -ComObject "Shell.Application").FileRun()

This does have the effect of flashing the PowerShell window for a moment, however

Or alternatively with

explorer "shell:::{2559a1f3-21d7-11d4-bdaf-00c04f60b9f0}"
Blackfish answered 22/9 at 4:51 Comment(0)
B
0

Using Windows Command (cmd.exe):

cmd /c 'explorer.exe Shell:::{2559a1f3-21d7-11d4-bdaf-00c04f60b9f0}'

Blackfish answered 22/9 at 4:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.