We often encounter a link or button to open a specified URL in WinForm or WPF, or to open a designated hard disk partition and folder in your computer.
Even "control Panel" related things, then how to 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)
Like what:
C # Code:
System.Diagnostics.Process ie = new System.Diagnostics.Process ();
Ie. Startinfo.filename = "IEXPLORE. EXE ";
Ie. Startinfo.arguments = @ "http://www.baidu.com";
Ie. Start ();
Simple Invocation Method:
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:
To open the panel for Add or Remove Programs:
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 of 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 use of rundll32.exe
--------------------------------------------------------------------------------
Command column: Rundll32.exe user.exe,restartwindows
Function: System restart
Command column: Rundll32.exe user.exe,exitwindows
Function: Shut down the system
Command column: Rundll32.exe shell32.dll,Control_RunDLL
Function: Display Control Panel
Command column: rundll32.exe shell32.dll,Control_RunDLL access.cpl,,1
Features: Display the Control Panel-secondary Options-Keyboard Options window
Command column: rundll32.exe shell32.dll,Control_RunDLL access.cpl,,2
Features: Display the Control Panel-secondary Options-Sound Options window
Command column: rundll32.exe shell32.dll,Control_RunDLL access.cpl,,3
Features: Display the Control Panel-Accessibility Options-Display Options window
Command column: rundll32.exe shell32.dll,Control_RunDLL access.cpl,,4
Function: Display the Control Panel-accessibility-mouse Option window
Command column: rundll32.exe shell32.dll,Control_RunDLL access.cpl,,5
Features: Display the Control Panel-Accessibility 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: Executes the Control Panel-Add New Printer wizard.
Command column: rundll32.exe shell32.dll,Control_RunDLL appwiz.cpl,,1
Features: Displays the Control Panel-Add/Remove Programs-install/uninstall panel.
Command column: rundll32.exe shell32.dll,Control_RunDLL appwiz.cpl,,2
Features: Displays the Control Panel-Add/Remove Programs-install Windows panel.
Command column: rundll32.exe shell32.dll,Control_RunDLL appwiz.cpl,,3
Features: Displays the Control Panel-Add/Remove Programs-Startup disk panel.
Command column: Rundll32.exe syncui.dll,briefcase_create
Function: 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
Features: Displays the dialog box for create shortcut, 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]
Function: 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 column: 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
Features: Displays the Display Properties-background Options window.
Command column: rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,1
Features: Displays the Display Properties-screen Saver Options window.
Command column: rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,2
Features: Displays the Display Properties-appearance Options window.
Command column: rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,3
Features: Displays the Display Properties-Properties Options window.
Command column: Rundll32.exe shell32.dll,shhelpshortcuts_rundll fontsfolder
Features: Displays the Fonts folder for Windows.
Command column: rundll32.exe shell32.dll,control_rundll main.cpl @3
Feature: also displays the Windows "Fonts" folder. Command column: Rundll32.exe shell32.dll,shformatdrive
Function: Displays the Format Soft Disk dialog box.
Command column: rundll32.exe shell32.dll,Control_RunDLL joy.cpl,,0
Function: Displays the "Control Panel-game controller-General" Options window.
Command column: rundll32.exe shell32.dll,Control_RunDLL joy.cpl,,1
Features: Displays the Control Panel-game controller-Advanced Options window.
Command column: rundll32.exe mshtml.dll,printhtml (HTML document)
Function: Print HTML document.
Command column: rundll32.exe shell32.dll,Control_RunDLL mlcfg32.cpl
Features: 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 column: rundll32.exe shell32.dll,control_rundll main.cpl @1
Features: Displays the Control Panel-keyboard Properties-speed Options window.
Command column: 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
Function: Displays the Windows "printer" folder.
Command column: rundll32.exe shell32.dll,control_rundll main.cpl @3
Function: 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" option window.
Command column: rundll32.exe shell32.dll,Control_RunDLL modem.cpl,,add
Function: Executes the Add New Modem wizard.
Command column: 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
Features: Displays the Control Panel-multimedia Properties-video property page.
Command column: rundll32.exe shell32.dll,Control_RunDLL mmsys.cpl,,2
Features: Displays the Control Panel-Multimedia Properties-midi property page.
Command column: rundll32.exe shell32.dll,Control_RunDLL mmsys.cpl,,3
Features: Displays the Control Panel-multimedia Properties-CD Music property page.
Command column: 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
Features: Displays the Control Panel-Sound Options window.
Command column: rundll32.exe shell32.dll,Control_RunDLL netcpl.cpl
Function: Displays the "Control Panel-Network" option 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}
Features: Displays the Open With dialog box for the specified profile (drive:/path/filename).
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
Features: 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-Regional Settings Properties-Regional Settings Options window.
Command column: rundll32.exe shell32.dll,Control_RunDLL intl.cpl,,1
Features: Displays the Control Panel-Regional Settings Properties-Number Options window.
Command column: rundll32.exe shell32.dll,Control_RunDLL intl.cpl,,2
Features: Displays the Control Panel-Regional Settings Properties-Currency Options window.
Command column: rundll32.exe shell32.dll,Control_RunDLL intl.cpl,,3
Features: Displays the Control Panel-Regional Settings Properties-time window.
Command column: rundll32.exe shell32.dll,Control_RunDLL intl.cpl,,4
Features: Displays the Control Panel-locale Properties-date Options window.
Command column: rundll32.exe desk.cpl,installscreensaver [screen saver file name]
Function: Set the specified screen protection profile to the screen saver of Windows and display the Screen Saver Properties window.
Command column: rundll32.exe shell32.dll,Control_RunDLL sysdm.cpl,,0
Features: Displays the Control Panel-System Properties-legacy Properties window.
Command column: rundll32.exe shell32.dll,Control_RunDLL sysdm.cpl,,1
Features: 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
Features: Displays the Control Panel-System Properties-performance Properties window. Command column: Rundll32.exe user.exe,restartwindows
Function: Forcibly closes all programs and restarts the machine.
Command column: Rundll32.exe user.exe,exitwindows
Function: Forcibly shuts down all programs and shuts down the machine.
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: Display the "Desktop Themes" options panel
C # Monitoring Program
2010-09-03 16:36:25| Classification:. NET2005 (C #) | Font subscription
The monitoring program referred to here refers to the use of this program, to monitor the operation of the other EXE program, if the EXE is abnormal and closed, the program will automatically restart the different
Regular procedures.
Body 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
{
private string exename = "Dos_xxt";
private string ExePath = @ "E:\DOS_XXT.exe";
private bool Runflag = false;
Private process[] myprocesses;
Public Form1 ()
{
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)
{
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 + "xor
The program is automatically restarted if it is always turned off! ");
}
}
}
net System.Diagnostics.Process.Start usage resolves a new instance of Word
Posted on 2011-06-02 15:15 codenote Read (645) Comments (0) Edit Collection
Original address
System.Diagnostics.Process.Start ();
This method is used to create a new process for example, you want to add a hyperlink to a program's menu to Baidu know so 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 this
If you have an open Web page then you will be redirected from that page to a new window with http://zhidao.baidu.com open.
Of course, you can also use it to open a local program, such as click a button to open the Registry Editor, it should be
System.Diagnostics.Process.Start (@ "C:\WINDOWS\regedit.exe"); problems encountered in System.Diagnostics.Process class applications 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 to the database
In 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!");
A few 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. Turn off the other word in the run
After the process, and then the implementation is sure that there is no problem.
After some research, finally found that there is no instance of Word 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, "Inference 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 is a Word instance 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 are no instances of Word running, or
{
WordProcess.StartInfo.FileName = FileName;
WordProcess.StartInfo.UseShellExecute = true;
}
Wordprocess.start ();
Wordprocess.waitforexit (); The current process waits until the Word instance exits.
Wordprocess.close ();
The Magical magic of System.Diagnostics.Process.Start