Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Call Shell Command

Call Shell Command

Scheduled Pinned Locked Moved C#
csharplinux
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Amauw Scritz
    wrote on last edited by
    #1

    Hi! The normal call x = Shell("Rundll32.exe shell32.dll,Control_RunDLL Sysdm.cpl ,0") How can this be done in C# Thanx in Advance.

    S A 2 Replies Last reply
    0
    • A Amauw Scritz

      Hi! The normal call x = Shell("Rundll32.exe shell32.dll,Control_RunDLL Sysdm.cpl ,0") How can this be done in C# Thanx in Advance.

      S Offline
      S Offline
      Stephane Rodriguez
      wrote on last edited by
      #2

      System.Diagnostics.Process.Start(...)

      1 Reply Last reply
      0
      • A Amauw Scritz

        Hi! The normal call x = Shell("Rundll32.exe shell32.dll,Control_RunDLL Sysdm.cpl ,0") How can this be done in C# Thanx in Advance.

        A Offline
        A Offline
        Andy Davey
        wrote on last edited by
        #3

        Its a bit more complicated but here is an example:

        using System;
        using System.Diagnostics;

        Process p = new Process();
        p.StartInfo = new ProcessStartInfo(@"Rundll32.exe shell32.dll,Control_RunDLL Sysdm.cpl, 0");
        p.StartInfo.UseShellExecute = true;
        p.Start();

        // and optionally
        p.WaitForExit();

        Andy He who knows and knows that he knows, is wise;  follow him_He who knows and knows not that he knows, is asleep;_  wake him_He who knows not, and knows that he knows not, is simple;_  teach him_He whoe knows not and knows not that he knows not, is a fool;_  kick him

        A 1 Reply Last reply
        0
        • A Andy Davey

          Its a bit more complicated but here is an example:

          using System;
          using System.Diagnostics;

          Process p = new Process();
          p.StartInfo = new ProcessStartInfo(@"Rundll32.exe shell32.dll,Control_RunDLL Sysdm.cpl, 0");
          p.StartInfo.UseShellExecute = true;
          p.Start();

          // and optionally
          p.WaitForExit();

          Andy He who knows and knows that he knows, is wise;  follow him_He who knows and knows not that he knows, is asleep;_  wake him_He who knows not, and knows that he knows not, is simple;_  teach him_He whoe knows not and knows not that he knows not, is a fool;_  kick him

          A Offline
          A Offline
          Amauw Scritz
          wrote on last edited by
          #4

          Thank you both :))

          A 1 Reply Last reply
          0
          • A Amauw Scritz

            Thank you both :))

            A Offline
            A Offline
            Amauw Scritz
            wrote on last edited by
            #5

            Thanx but both the solutions gives errors. System.ComponentModel.Win32Exception: The system cannot find the file specified at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo) at System.Diagnostics.Process.Start() at TestWindowsForms.Form1.menuItem24_Click(Object sender, EventArgs e) in d:\visual studio projects\art\testwindowsforms\form1.cs:line 661 at System.Windows.Forms.MenuItem.OnClick(EventArgs e) at System.Windows.Forms.MenuItemData.Execute() at System.Windows.Forms.Command.Invoke() at System.Windows.Forms.Control.WmCommand(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.ContainerControl.WndProc(Message& m) at System.Windows.Forms.Form.WndProc(Message& m) at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) Yes I've check the command " Rundll32.exe shell32.dll,Control_RunDLL Sysdm.cpl, 0 " inside the Start/Run dialog in windows 2000 and it works. But why doesn't it work when called from the program. Check with other *.cpl files as well. Any help would be Greatly appreciated !!! :((

            S 1 Reply Last reply
            0
            • A Amauw Scritz

              Thanx but both the solutions gives errors. System.ComponentModel.Win32Exception: The system cannot find the file specified at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo) at System.Diagnostics.Process.Start() at TestWindowsForms.Form1.menuItem24_Click(Object sender, EventArgs e) in d:\visual studio projects\art\testwindowsforms\form1.cs:line 661 at System.Windows.Forms.MenuItem.OnClick(EventArgs e) at System.Windows.Forms.MenuItemData.Execute() at System.Windows.Forms.Command.Invoke() at System.Windows.Forms.Control.WmCommand(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.ContainerControl.WndProc(Message& m) at System.Windows.Forms.Form.WndProc(Message& m) at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) Yes I've check the command " Rundll32.exe shell32.dll,Control_RunDLL Sysdm.cpl, 0 " inside the Start/Run dialog in windows 2000 and it works. But why doesn't it work when called from the program. Check with other *.cpl files as well. Any help would be Greatly appreciated !!! :((

              S Offline
              S Offline
              Stephane Rodriguez
              wrote on last edited by
              #6

              Solution1 : async call

              System.Diagnostics.Process.Start("Rundll32",
              "shell32.dll,Control_RunDLL Sysdm.cpl ,0");

              Solution2 : sync call

              Process p = new Process();
              p.StartInfo = new ProcessStartInfo("Rundll32.exe",
              "shell32.dll,Control_RunDLL Sysdm.cpl , 0");
              p.StartInfo.UseShellExecute = true;
              p.Start();// and optionally
              p.WaitForExit();

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups