C# Using a Shell from a Windows Application

I am inquiring on how to shell out from a windows application to use the command prompt window as the type of display. 

For example:  I want the user to be able to click a button and that button open the command prompt and run a particular script and display those results in the command prompt window. 

Any ideas

Thanks


Answer this question

C# Using a Shell from a Windows Application

  • bj16060

    Try calling RunDLL32 directly:



    try
    {
    System.Diagnostics.Process proc = new System.Diagnostics.Process();
    proc.StartInfo.FileName = "rundll32.exe";
    proc.StartInfo.Arguments = "shell32.dll,Control_RunDLL ncpa.cpl,,0";
    proc.Start();
    }
    catch { }




    That will bring up the Network Connection.

    Regards,

    -chris



  • telek

    Hi,

    Try this:

    System.Diagnostics.Process p = new System.Diagnostics.Process();

    p.StartInfo.UseShellExecute = false;
    p.StartInfo.FileName = "cmd.exe";
    p.StartInfo.Arguments = "/k dir *.*";
    p.Start();


    The /k tells the command window to remain until user pressed the close button or typed exit.


    -chris



  • RSyb

    someone help me out. i ended up using this. basically the same.

    try

    {

    ProcessStartInfo NetworkConnections = new ProcessStartInfo("rundll32.exe", "shell32.dll,Control_RunDLL ncpa.cpl");

    Process.Start(NetworkConnections);

    }

    catch { }

    thanks


  • BatchBoy

    Hi, i'm developing an app where i want to detect internet connection status.

    I have a linked label on a statusbar (where i show if i'm connected or not). On the click event of the label, i have this code:

    try
    {
    System.Diagnostics.Process proc = new System.Diagnostics.Process();
    proc.StartInfo.UseShellExecute = false;
    proc.StartInfo.FileName = "cmd";
    proc.StartInfo.Arguments = "rundll32.exe shell32.dll,Control_RunDLL ncpa.cpl,,0";
    proc.Start();
    //proc.WaitForExit();
    }
    catch { }

    As you can tell, the idea is to show the Network Connections avaible on the target system.
    I searched a while for it, and since C# doesn't support Shell, this is supossed to be the way.

    I'm just getting the cmd "poped up". It doesn't call the arguments. When I copy/paste the arguments string on cmd, i get the Network Connections window opened, but cmd remains open as well.

    Is there any other way to call the control panel applets in c# If not, is there any way that to emulate the "Run..." from Start menu with c#

    Thanks for your time fellas.

  • C# Using a Shell from a Windows Application