Call Shell Command
-
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.
-
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.
System.Diagnostics.Process.Start(...)
-
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.
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
-
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
Thank you both :))
-
Thank you both :))
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 !!! :((
-
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 !!! :((
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();