10

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?

5 Answers 5

10

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.

11

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

explorer.exe Shell:::{2559a1f3-21d7-11d4-bdaf-00c04f60b9f0}
2
  • 3
    This is what I was exactly looking for.Many thanks :)
    – Atul
    May 28, 2015 at 5:13
  • it works, tks, but how to tell the Run box to remember its position on screen?
    – Dan D.
    Jun 13, 2020 at 5:39
7

Below works for my 32-bit Windows:

c:\WINDOWS\system32\rundll32.exe shell32.dll,#61

Any one knows the 64-bit version?

5
  • 2
    Works on Windows 7 64 bit as well.
    – DavidPostill
    May 6, 2016 at 9:08
  • Good, so this one line is better than selected answer I think.
    – James Yang
    May 6, 2016 at 15:03
  • Works on Windows 8.1 64-bit as well, but without the "Type the name of a program..." inscription, that's blank
    – user373230
    Oct 15, 2016 at 16:21
  • 2
    %WINDIR%\SysWOW64\rundll32.exe shell32.dll,#61 Nov 25, 2016 at 14:07
  • Interesting -- when I run this from a cmd window, the Run dialog appears in the middle of the cmd window (positioning). When I run the explorer.exe Shell... command per @CoolCmd, it appears above the start menu, where it would if pressing WIN + R...
    – CJBS
    May 16, 2019 at 17:57
2

I am only an amateur programmer, but it strikes me it would be shorter and more efficient to put the command for what ever you want in the batch file, rather than the risky procedure of calling for the Run dialog box to open.

Bad things could happen to your batch file if a user was present when the .bat ran. It just seems neater programming to give a command-line instruction from within that batch file.

1

The laziest way is to use AutoHotKey to literally send the Win+R command to the operating system:

SendInput, {LWin down}r{LWin up}

I went ahead and uploaded a ZIP containing an AutoHotKey script and a compiled .exe of the script. I apologize if there's a "better" way of handling this; once I find a way that works I move on to the next thing!

1
  • 4
    A disadvantage of this approach is it requires Explorer to be running and handle the Win + R hotkey. If Explorer is not running, nothing will happen - while the run dialog does not depend on Explorer, this hotkey does.
    – Bob
    Jan 13, 2013 at 12:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .