Open Run... dialog from command

I would like to run the Run... dialog (the Win+R) from a batch command? There is an shotcut to it in C:\Users\USER\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\System Tools but that shotcut goes nowhere, the target is just "Run..." and the target directory is my desktop.

How can I run the dialog from a command?


Solution 1:

Vista or later

If you are on Windows Vista or later, it will come with PowerShell. The PowerShell one-liner (New-Object -ComObject "Shell.Application").FileRun() will work.

You can run this directly from the legacy command line (or within a batch file) with the following:

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

This is an adaptation of the VBScript command outlined below.


Pre-Vista

For older versions of Windows (this will also work in newer versions, but requires an additional file), you can do this via VBScript, using the Shell object:

dim oShell = CreateObject("shell.application")
oShell.FileRun()

Shrinking it into one line:

CreateObject("shell.application").FileRun()

Simple put that line into its own plain text file and save it with the extension .vbs, e.g. ShowRunDialog.vbs. Then run ShowRunDialog.vbs from the command line.

This indirectly runs the RunFileDlg function contained within shell32.dll. See here.

Solution 2:

This command can be launched from any program/script to show "Run" dialog:

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