The Magical magic of System.Diagnostics.Process.Start
Category: C#+winform 2009-04-05 21:09 459 people Read reviews (0) Favorites Reports We often encounter a link or button in WINFORM or WPF to open a specified URL, Or if you need to open a specific hard disk partition and folder in your computer, or even something related to the control Panel, how do you do it? The answer is to use System.Diagnostics.Process.Start (). Its role is to invoke external commands. Let's take a look at its invocation method: Process.Start () Process.Start (ProcessStartInfo) Process.Start (String) Process.Start (string , string) Process.Start (String, String, SecureString, String) Process.Start (String, String, String, SecureString, String) For example: C # Code: System.Diagnostics.Process ie = new System.Diagnostics.Process (); ie. startinfo.filename = "IEXPLORE. EXE "; ie. startinfo.arguments = @ "http://www.baidu.com"; IE. Start (); Concise call mode: System.Diagnostics.Process.Start ("http://www.baidu.com"); Of course, you can also use other browsers, such as proud tour instead of IE: string mathonpath = @ "c:/program Files/maxthon//maxthon.exe"; System.Diagnostics.Process p = new System.Diagnostics.Process (); //Set Program name p.startinfo.filename = Mathonpath; p.startinfo.arguments = @ "c:/"; P.start (); If you want to open c:/with the Explorer, you can do this: System.Diagnostics.Process.Start ("Explorer.exe", @ "c:/"); More people might ask, "I'm going to open the Add or Remove Programs Panel or the control Panel, OK?" "The answer is YES!" How to do? The answer is to call rundll32.exe, for example: Open the "Add or Remove Programs" Panel: System.Diagnostics.Process.Start ("rundll32.exe", @ "Shell32.dll,control_ RunDLL appwiz.cpl,,1 "); The following "shell32.dll,Control_RunDLL appwiz.cpl,,1" is the parameter required to invoke the command. Here's a description, which is similar to the use in Delphi: ShellExecute (Handle, ' open ', ' rundll32.exe ', ' shell32.dll,control_rundll Sysdm.cpl ', nil,sW_show); winexec (' rundll32.exe shell32.dll,control_rundll sysdm.cpl ', SW_SHOW); About the purpose of rundll32.exe --------------------------------------------------------------------------------command columns: rundll32.exe user.exe,restartwindows function: System restart command column: rundll32.exe user.exe,exitwindows function: Shutdown system command column: Rundll32.exe shell32.dll,control_rundll function: Display control Panel Command column: rundll32.exe shell32.dll,control_rundll access.cpl,,1 function : Display control Panel-secondary Options-Keyboard Options window Command column: rundll32.exe shell32.dll,control_rundll access.cpl,,2 function: Display "Control Panel-accessibility-sound" Options windows Command columns: rundll32.exe shell32.dll,control_rundll access.cpl,,3 Features: Display the Control Panel-Accessibility-Display Options window command columns: rundll32.exe shell32.dll,Control_RunDLL access.cpl,,4 Features: Display control Panel-secondary Options-Mouse Options window Command column: rundll32.exe shell32.dll,Control_RunDLL access.cpl,,5 Features: Display control Panel-secondary Options-Legacy Options window Command column: Rundll32.exe Shell32.dll,control_ RunDLL sysdm.cpl @1 Function: Executes the Control Panel-Add New Hardware wizard. Command column: Rundll32.exe SHELL32.DLL,SHHELPSHORTCUTs_rundll addprinter function: Execute the "Control Panel-Add new Printer" wizard. Command column: rundll32.exe shell32.dll,control_rundll appwiz.cpl,,1 function: Displays the Control Panel-Add/Remove Programs-install/uninstall panel. Command column: rundll32.exe shell32.dll,control_rundll appwiz.cpl,,2 function: Displays the Control Panel-Add/Remove Programs-install Windows panel. Command column: rundll32.exe shell32.dll,control_rundll appwiz.cpl,,3 function: Displays the Control Panel-Add/Remove Programs-Startup disk panel. Command column: Rundll32.exe syncui.dll,briefcase_create feature: Create a new "My Briefcase" on the desktop. Command column: rundll32.exe diskcopy.dll,diskcopyrundll function: Display copy floppy window command column: Rundll32.exe apwiz.cpl,newlinkhere %1 function: Displays the dialog box for "Create Shortcut", where the location of the shortcut is determined by the%1 parameter. Command column: rundll32.exe shell32.dll,control_rundll timedate.cpl,,0 function: Displays the date and Time Options window. Command column: rundll32.exe shell32.dll,control_rundll timedate.cpl,,1 function: Displays the Time Zone Options window. Command column: rundll32.exe rnaui.dll,rnadial [Name of a dial-up connection] feature: Displays the Dial-up window for a dial-up connection. If you have a dial-up connection, the current Connection status window is displayed. Command columns: rundll32.exe rnaui.dll,rnawizard Features: Displays the windows of the new Dial-up Connection wizard. Command column: Rundll32.exe Shell32.dll,conTrol_rundll desk.cpl,,0 function: Displays the "Display Properties-background" option window. Command column: rundll32.exe shell32.dll,control_rundll desk.cpl,,1 function: Displays the Display Properties-screen saver option window. Command column: rundll32.exe shell32.dll,control_rundll desk.cpl,,2 function: Displays the Display Properties-appearance option window. Command column: rundll32.exe shell32.dll,control_rundll desk.cpl,,3 function: Displays the Display Properties-Properties Options window. Command column: Rundll32.exe shell32.dll,shhelpshortcuts_rundll fontsfolder function: Displays the Windows "Fonts" folder. Command column: rundll32.exe shell32.dll,control_rundll main.cpl @3 feature: The same is the "Fonts" folder that displays Windows. Command column: rundll32.exe shell32.dll,shformatdrive function: Displays the Format Floppy dialog box. Command column: rundll32.exe shell32.dll,control_rundll joy.cpl,,0 function: Displays the "Control Panel-game controller-General" option window. Command column: rundll32.exe shell32.dll,control_rundll joy.cpl,,1 function: Displays the Control Panel-game controller-Advanced Options window. Command columns: rundll32.exe mshtml.dll,printhtml (HTML document) Features: Print HTML documents. Command column: rundll32.exe shell32.dll,control_rundll mlcfg32.cpl Feature: Displays the Microsoft Exchange General Options window. Command column: Rundll32.exe Shell32.dll,control_rundll main.cpl @0 function: Displays the "Control Panel-Mouse" option. Command columns: rundll32.exe shell32.dll,control_rundll main.cpl @1 Features: Displays the Control Panel-keyboard Properties-speed Options window. Command columns: rundll32.exe shell32.dll,control_rundll main.cpl @1,,1 Features: Displays the Control Panel-keyboard Properties-Language Options window. Command column: rundll32.exe shell32.dll,control_rundll main.cpl @2 feature: Displays the Windows printer folder. Command column: rundll32.exe shell32.dll,control_rundll main.cpl @3 feature: Displays the Windows "Fonts" folder. Command column: rundll32.exe shell32.dll,control_rundll main.cpl @4 function: Displays the control Panel-Input Method Properties-Input Method Options window. Command column: rundll32.exe shell32.dll,control_rundll modem.cpl,,add function: Perform the Add New Modem wizard. Command columns: rundll32.exe shell32.dll,control_rundll mmsys.cpl,,0 Features: Displays the Control Panel-Multimedia Properties-Audio property page. Command column: rundll32.exe shell32.dll,control_rundll mmsys.cpl,,1 function: Displays the Control Panel-multimedia Properties-video property page. Command column: rundll32.exe shell32.dll,control_rundll mmsys.cpl,,2 function: Displays the Control Panel-Multimedia Properties-midi property page. Command columns: rundll32.exe shell32.dll,control_rundll mmsys.cpl,,3 Features: Display the Control Panel-multimedia Properties-CD Music Property Page。 Command columns: rundll32.exe shell32.dll,control_rundll mmsys.cpl,,4 Features: Displays the Control Panel-Multimedia Properties-Devices property page. Command column: rundll32.exe shell32.dll,control_rundll mmsys.cpl @1 function: Displays the Control Panel-Sound Options window. Command column: rundll32.exe shell32.dll,control_rundll netcpl.cpl function: Displays the Control Panel-Network Options window. Command column: rundll32.exe shell32.dll,control_rundll odbccp32.cpl function: Displays the ODBC32 Data Management Options window. Command column: Rundll32.exe shell32.dll,openas_rundll {drive:/path/filename} function: Displays the specified file (drive:/path/filename) " Open With dialog box. Command column: rundll32.exe shell32.dll,control_rundll password.cpl function: Displays the Control Panel-Password Option window. Command column: rundll32.exe shell32.dll,control_rundll powercfg.cpl function: Displays the Control Panel-Power Management Properties Options window. Command column: Rundll32.exe shell32.dll,shhelpshortcuts_rundll printersfolder function: Displays the Windows printer folder. (with rundll32.exe shell32.dll,Control_RunDLL main.cpl @2) Command column: rundll32.exe shell32.dll,Control_RunDLL intl.cpl,,0 Features: Displays the Control Panel-locale Properties-Regional Settings Options window. Command column: rundll32.exe shell32.dll,Control_RunDLL intl.cpl,,1&nbSp Features: Displays the Control Panel-Regional Settings Properties-Number Options window. Command column: rundll32.exe shell32.dll,control_rundll intl.cpl,,2 function: Displays the Control Panel-locale Properties-Currency Options window. Command column: rundll32.exe shell32.dll,control_rundll intl.cpl,,3 function: Displays the Control Panel-locale Properties-time window. Command column: rundll32.exe shell32.dll,control_rundll intl.cpl,,4 function: Displays the Control Panel-locale Properties-date Option window. Command column: rundll32.exe desk.cpl,installscreensaver [screen saver file name] function: Set the specified screen protection profile to the screensaver of Windows and display the Screen Protection Properties window. Command column: rundll32.exe shell32.dll,control_rundll sysdm.cpl,,0 function: Displays the Control Panel-System Properties-legacy Properties window. Command column: rundll32.exe shell32.dll,control_rundll sysdm.cpl,,1 function: Displays the Control Panel-System Properties-Device Manager Properties window. Command column: rundll32.exe shell32.dll,control_rundll sysdm.cpl,,2 function: Displays the Control Panel-System Properties-Hardware profile Properties window. Command column: rundll32.exe shell32.dll,control_rundll sysdm.cpl,,3 function: Displays the Control Panel-System Properties-performance Properties window. Command column: rundll32.exe user.exe,restartwindows function: Forcibly shuts down all programs and restarts the machine. Command column: rundll32.exe user.exe,exitwindows function: Forcibly shuts down all programs and shuts down. Command column: rundll32.exe shell32.dll,Control_RunDLL telephon.cpl Features: Display the Dialing Properties Options window Command column: rundll32.exe shell32.dll,Control_RunDLL themes.cpl Features: Displays the desktop Themes options panel C # monitoring program 2010-09-03 16:36:25| classification: . NET2005 (C #) | Font subscription The monitoring program described here refers to the use of this program, to monitor the operation of another EXE program, if the EXE is closed, the program will automatically restart the exception program. Text start: Using System; Using System.Collections.Generic; Using System.ComponentModel; Using System.Data; Using System.Drawing; Using System.Text; Using System.Windows.Forms; Using system.diagnostics;//introduces the Process class namespace Whbservertask { public partial class Form1:form &nbs p; { private string exename = "Dos_xxt"; private String ExePath = @ "E:\DOS_XXT.exe"; private bool Runflag = false; private process[] myprocesses; public Form1 ()    &NBsp; { InitializeComponent (); } private void Timer1_Tick ( Object sender, EventArgs e) { Whbtask (); } private void Whbtask () { ListBox1.Items.Add (DateTime.Now.ToString () + ":" + "program polling, running normally! "); myprocesses = process.getprocesses (); foreach (Process myprocess in Myprocesses) { //Find out if you are running if (MyProcess.ProcessName.CompareTo (exename) = = 0) { Runflag = true; } } if (! Runflag)//If not running, start { System.Diagnostics.Process.Start (ExePath); ListBox1.Items.Add ( DateTime.Now.ToString () + ":" + exepath+ "program restarts once!" "); } Runflag = false; } private void Button1_Click (object sender, EventArgs e) & nbsp; {   &Nbsp; listBox1.Items.Clear (); } private void Form1_Load ( Object sender, EventArgs e) { listBox1.Items.Add ("description: This program for" + ExePath + "Running monitoring program, polling every 1 hours, if" + ExePath + "Abnormal shutdown, then automatically restart the program!) "); } }} NET System.Diagnostics.Process.Start usage Fix Word new instance Posted on 2011-06-02 15:15 codenote Read (645) Comments (0) Edit Collection Original address System.diagno Stics. Process.Start (); This method is used to create a new process such as you want to add a hyperlink to the menu of a program to Baidu know then you can use this method to achieve System.Diagnostics.Process.Start ("iexplore.exe", "http/ Zhidao.baidu.com "); The first argument above can be omitted, but if you have an open page before, then you will jump from that page to http://zhidao.baidu.com open a new window, and of course you can use it to open a local program. For example, clicking on a button opens the Registry Editor, which should be System.Diagnostics.Process.Start (@ "C:\WINDOWS\REGEDIT.EXe "); System.Diagnostics.Process class application in. NET the client program that you develop needs to create a Word document from the image field of the database, and then call the Word program open, and the user edits and saves it back into the database. Where word is called to open the document with the System.Diagnostics.Process class, the relevant code is as follows: String temppath = System.Environment.GetEnvironmentVariable ("TEMP"); String fileName = Path.Combine (TempPath, "01.doc"); Process wordprocess = new process (); WordProcess.StartInfo.FileName = FileName; WordProcess.StartInfo.Verb = "edit"; WordProcess.StartInfo.UseShellExecute = true; Wordprocess.start (); Wordprocess.waitforexit (); Wordprocess.close (); MessageBox.Show ("Word exited!"); days ago has been good, but today in the implementation to Wordprocess.waitforexit (); In this sentence, an unexpected message is "there is no process associated with this object." A closer look at the relevant documentation on MSDN is not explained in much detail, but this is included in the WaitForExit () method's documentation that mentions a possible exception. It suddenly occurred to me that it was possible that the word process had been opened, so it was not associated with the current process, so it would have happened. After you turn off the other word processes that are running, it is no longer a problem to do so. After some research, finally found that there is no word instance running in the case can achieve the requirements of the previous article method, the code is as follows: string TempPath = System.Environment.GetEnvironmentVariable ("TEMP"); string fileName= Path.Combine (TempPath, "reasoning 01.doc"); string Winwordpath = ""; //Determine if a Word instance is already running in the system. process[] wordprocesses = Process.getprocessesbyname ("Winword"); foreach (Process process in wordprocesses) { Debug.WriteLine ( Process. MainWindowTitle); Winwordpath = process. mainmodule.filename; //If any, get the fully qualified name of the Winword.exe. break; } Process wordprocess = new Process (); if (winwordpath.length > 0) //If there are instances of Word running, Use the/w parameter to force a new instance to be started and pass the file name as a parameter. { wordProcess.StartInfo.FileName = winwordpath; Wordprocess.startinfo.UseShellExecute = false; wordProcess.StartInfo.Arguments = fileName + "/w"; } else //If there is no Word instance running, or { wordProcess.StartInfo.FileName = filename; WordProcess.StartInfo.UseShellExecute = true; } Wordprocess.start (); wordprocess.waitforexit (); //The current process is waiting until the Word instance exits. Wordprocess.close ();
"Reprint System.Diagnostics.Process.Start's Magical Magic"