Invoke the “Run” command

I am trying to invoke the "Run" dialogue box that is often on the Start Menu - I did some research and have only managed to find one way of accessing it (using "Windows Key" + R).

So I assume simulating key strokes e.g.:

SendKeys.Send("{TEST}") 

would do the job? Although how can you simulate the "Windows" key on the keyboard?

I am sure there is an easier way of doing this - without using sendkeys - anyone have any ideas?

Answers


You can use PInvoke to invoke Run dialog.

[Flags()]
public enum RunFileDialogFlags : uint
{

    /// <summary>
    /// Don't use any of the flags (only works alone)
    /// </summary>
    None = 0x0000,    

    /// <summary>
    /// Removes the browse button
    /// </summary>
    NoBrowse = 0x0001,

    /// <summary>
    /// No default item selected
    /// </summary>
    NoDefault = 0x0002,

    /// <summary>
    /// Calculates the working directory from the file name
    /// </summary>
    CalcDirectory = 0x0004,

    /// <summary>
    /// Removes the edit box label
    /// </summary>
    NoLabel = 0x0008,

    /// <summary>
    /// Removes the separate memory space checkbox (Windows NT only)
    /// </summary>
    NoSeperateMemory = 0x0020
}

we need to Import the DLL using the DllImport attribute.

[DllImport("shell32.dll", CharSet = CharSet.Auto, EntryPoint = "#61", SetLastError = true)]

static extern bool SHRunFileDialog(IntPtr hwndOwner, 
                                   IntPtr hIcon, 
                                   string lpszPath,
                                   string lpszDialogTitle, 
                                   string lpszDialogTextBody, 
                                   RunFileDialogFlags uflags);

Implementation:

private void ShowRunDialog(object sender, RoutedEventArgs e)
{
    SHRunFileDialog(IntPtr.Zero, 
                    IntPtr.Zero, 
                    "c:\\",
                    "Run Dialog using PInvoke",
                    "Type the name of a program, folder or internet address 
            and Windows will open that for you.",
                    RunFileDialogFlags.CalcDirectory);

}


Need Your Help

How to provide config file for Ruby command line utility written in Ruby?

ruby command-line configuration-files

I have a command line utility written in Ruby using GLI framework. I would like to have configuration for my command line utility in my home directory, using Ruby itself as DSL to handle it (simila...

Angular: Set a default value in ng-repeat if an item's property does not exist

javascript angularjs angularjs-ng-repeat ng-repeat

Is it possible possible during ng-repeat that if the current item does not have a certain property, I assign a default value for it, something like that:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.