System. Diagnostics. Process. Start, systemdiagnostics

Source: Internet
Author: User
Tags intl

System. Diagnostics. Process. Start, systemdiagnostics

We often encounter a problem of clicking a link or button in Winform or WPF to open a specified website or opening a specified hard disk partition and folder on the computer,
How can we do something even related to "Control Panel?
The answer is to use System. Diagnostics. Process. Start (). It is used to call external commands.
Let's take a look at its call method:
Process. Start ()
Process. Start (ProcessStartInfo)
Process. Start (String)
Process. Start (String, String)
Process. Start (String, String, SecureString, String)
Process. Start (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 ();
Simple call method:
System. Diagnostics. Process. Start ("http://www.baidu.com ");
Of course, you can also use other browsers, such as aoyou rather than IE:
String mathonPath = @ "C:/Program Files/Maxthon // Maxthon.exe ";
System. Diagnostics. Process p = new System. Diagnostics. Process (); // set the program name
P. StartInfo. FileName = mathonPath;
P. StartInfo. Arguments = @ "c :/";
P. Start ();
If you want to use the resource manager to open C:/, you can do this:
System. Diagnostics. Process. Start ("assumer.exe", @ "c :/");
Someone may ask, "Can I open the" add or delete programs "Panel or control panel related content ?" The answer is yes!
How to do it? The answer is to call rundll32.exe, for example:
Open the "add or delete programs" panel:
System. Diagnostics. Process. Start ("rundll32.exe", @ "shell32.dll, Control_RunDLL appwiz. cpl, 1 ");
The following "shell32.dll, Control_RunDLL appwiz. cpl, and 1" are the parameters required to call the command.
This is similar to using 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 );
Usage of rundll32.exe
--------------------------------------------------------------------------------
Command column: rundll32.exe user.exe, restartwindows
Function: restarts the system.
Command column: rundll32.exe user.exe, exitwindows
Function: disable 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
Function: displays the "control panel-Auxiliary options-keyboard" option window.
Command column: rundll32.exe shell32.dll, Control_RunDLL access. cpl, 2
Function: displays the "control panel-Auxiliary options-sound" option window.
Command column: rundll32.exe shell32.dll, Control_RunDLL access. cpl, 3
Function: displays the "control panel-Auxiliary options-display" option window.
Command column: rundll32.exe shell32.dll, Control_RunDLL access. cpl, 4
Function: displays the control panel-secondary option-mouse option window.
Command column: rundll32.exe shell32.dll, Control_RunDLL access. cpl, 5
Function: displays the "control panel-Auxiliary options-traditional" option window.
Command column: rundll32.exe shell32.dll, Control_RunDLL sysdm. cpl @ 1
Function: run the "control panel-add new hardware" Wizard. Command column: rundll32.exe shell32.dll, SHHelpShortcuts_RunDLL AddPrinter
Function: run the control panel-add new printer wizard.
Command column: rundll32.exe shell32.dll, Control_RunDLL appwiz. cpl, 1
Function: the "control panel-Add/delete programs-install/uninstall" panel is displayed.
Command column: rundll32.exe shell32.dll, Control_RunDLL appwiz. cpl, 2
Function: the "control panel-Add/delete programs-install Windows" panel is displayed.
Command column: rundll32.exe shell32.dll, Control_RunDLL appwiz. cpl, 3
Function: the "control panel-Add/delete programs-boot disk" panel is displayed.
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: displays the copy disk Window.
Command column: rundll32.exe apwiz. cpl, NewLinkHere % 1
Function: the "Create shortcut" dialog box is displayed. The location of the created shortcut is determined by the % 1 parameter.
Command column: rundll32.exe shell32.dll, Control_RunDLL timedate. cpl, 0
Function: displays the "Date and Time" option window.
Command column: rundll32.exe shell32.dll, Control_RunDLL timedate. cpl, 1
Function: displays the "Time Zone" option window.
Command column: rundll32.exe rnaui. dll, RnaDial [name of a dial-up connection]
Function: displays the dialing window for a dial-up connection. If a dial-up connection has been established, the current connection status window is displayed.
Command column: rundll32.exe rnaui. dll, RnaWizard
Function: displays the window 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 "show properties-properties" option window.
Command column: rundll32.exe shell32.dll, SHHelpShortcuts_RunDLL FontsFolder
Function: display the "font" folder of Windows.
Command column: rundll32.exe shell32.dll, Control_RunDLL main. cpl @ 3
Function: displays the "font" folder of Windows. Command column: rundll32.exe shell32.dll, SHFormatDrive
Function: displays the formatting 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" option window.
Command column: rundll32.exe mshtml. dll, PrintHTML (HTML document)
Function: Print HTML documents.
Command column: rundll32.exe shell32.dll, Control_RunDLL ml1_32.cpl
Function: 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
Function: displays the "control panel-keyboard properties-speed" option window.
Command column: rundll32.exe shell32.dll, Control_RunDLL main. cpl @ 1, 1
Function: displays the "control panel-keyboard properties-language" option 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 "font" 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: run the Add new modem wizard.
Command column: rundll32.exe shell32.dll, Control_RunDLL mmsys. cpl, 0
Function: 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 column: rundll32.exe shell32.dll, Control_RunDLL mmsys. cpl, 3
Function: displays the "control panel-multimedia properties-CD music" property page.
Command column: rundll32.exe shell32.dll, Control_RunDLL mmsys. cpl, 4
Function: 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 option 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 option window.
Command column: rundll32.exe shell32.dll, OpenAs_RunDLL {drive:/path/filename}
Function: displays the open mode dialog box for the specified file (drive:/path/filename.
Command column: rundll32.exe shell32.dll, Control_RunDLL password. cpl
Function: the "control panel-Password" option window is displayed.
Command column: rundll32.exe shell32.dll, Control_RunDLL powercfg. cpl
Function: displays the "control panel-Power Management Properties" option window.
Command column: rundll32.exe shell32.dll, SHHelpShortcuts_RunDLL PrintersFolder
Function: displays the Windows "Printer" folder. (Same as rundll32.exe shell32.dll, Control_RunDLL main. cpl @ 2)
Command column: rundll32.exe shell32.dll, Control_RunDLL intl. cpl, 0
Function: the "control panel-region settings properties-region Settings" option window is displayed.
Command column: rundll32.exe shell32.dll, Control_RunDLL intl. cpl, 1
Function: displays the "control panel-region settings properties-numbers" option window.
Command column: rundll32.exe shell32.dll, Control_RunDLL intl. cpl, 2
Function: the "control panel-region settings properties-currency" option window is displayed.
Command column: rundll32.exe shell32.dll, Control_RunDLL intl. cpl, 3
Function: displays the "control panel-region settings property-time" option window.
Command column: rundll32.exe shell32.dll, Control_RunDLL intl. cpl, 4
Function: displays the "control panel-region settings properties-Date" option window.
Command column: rundll32.exe desk. cpl, InstallScreenSaver [Screen saver file name]
Function: sets the specified screen saver file to Windows and displays the screen saver Properties window.
Command column: rundll32.exe shell32.dll, Control_RunDLL sysdm. cpl, 0
Function: displays the "control panel-system properties-traditional" attribute 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 configuration file" attribute window.
Command column: rundll32.exe shell32.dll, Control_RunDLL sysdm. cpl, 3
Function: displays the "control panel-system properties-performance" attribute window. Command column: rundll32.exe user.exe, restartwindows
Function: forcibly shut down all programs and restart the machine.
Command column: rundll32.exe user.exe, exitwindows
Function: forcibly shut down all programs and shut down them.
Command column: rundll32.exe shell32.dll, Control_RunDLL telephon. cpl
Function: displays the "dial property" option window.
Command column: rundll32.exe shell32.dll, Control_RunDLL themes. cpl
Function: displays the desktop theme option panel.
 
C # Monitoring Program
16:36:25 | category:. NET2005 (c #) | font size subscription
The monitoring program mentioned here refers to the use of this program to monitor another EXE program running on the local machine. If this EXE is closed due to an exception, the program will automatically restart the exception.
Regular Program.
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; // introduce 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 timereffectick (object sender, EventArgs e)
{
Whbtask ();
} Private void whbtask ()
{
ListBox1.Items. Add (DateTime. Now. ToString () + ":" + "program polling, running properly! ");
MyProcesses = Process. GetProcesses ();
Foreach (Process MyProcess in MyProcesses)
{
// Check whether the instance is running
If (MyProcess. ProcessName. CompareTo (ExeName) = 0)
{
RunFlag = true;
}
}
If (! RunFlag) // start if it is not running
{
System. Diagnostics. Process. Start (ExePath );
ListBox1.Items. Add (DateTime. Now. ToString () + ":" + ExePath + "restart once! ");

}
RunFlag = false;

}
Private void button#click (object sender, EventArgs e)
{
ListBox1.Items. Clear ();
}
Private void Form1_Load (object sender, EventArgs e)
{
ListBox1.Items. Add ("NOTE: This program is a" + ExePath + "Running Monitoring Program, which polls once every hour. If" + ExePath + "is different
The program is automatically restarted if it is often disabled! ");
}
}
}
 
In net, the usage of System. Diagnostics. Process. Start solves the problem of a new word instance.
Posted on CodeNote reading (645) Comments (0) EDIT favorites
Original article address
 
System. Diagnostics. Process. Start ();
This method is used to create a new process. For example, if you want to add a hyperlink to the menu of a program to Baidu, you can use this method.
System. Diagnostics. Process. Start ("iexplore.exe", "http://zhidao.baidu.com"); the first parameter can be omitted, but if
You have opened the web page will jump from that web page to the http://zhidao.baidu.com did not open, then open a new window
Of course, you can also use it to open a local program. For example, if you 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 applications in. NET
A self-developed client program needs to create a Word document from the Image field of the database, then call the Word program to open it, the user edits and saves it, And then stores it in the database.
. The System. Diagnostics. Process class is used to call the Word to open the document. 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! ");
 
It has been easy to use for a few days, but an error occurred while executing wordProcess. WaitForExit () today. The message is "no process associated with this object ".
The relevant documentation in MSDN is not explained in detail, but it is included in the documents of the WaitForExit () method.
Suddenly, is it possible that the Word process has been opened, so it is not associated with the current process, so this accident occurs. Turn off other running Word
After the process, the execution is OK.
After some research, I finally found the method that can meet the requirements in the previous article when there is no Word instance running. The Code is as follows:
 
 
String tempPath = System. Environment. GetEnvironmentVariable ("TEMP ");
String fileName = Path. Combine (tempPath, "reasoning 01.doc ");
String winwordPath = "";

// Determine whether a Word instance is running in the system.
Process [] wordProcesses = Process. GetProcessesByName ("winword ");
Foreach (Process process in wordProcesses)
{
Debug. WriteLine (process. MainWindowTitle );
WinwordPath = process. MainModule. FileName; // obtain the fully qualified name of Winword.exe if any.
Break;
}

Process wordProcess = new Process ();

If (winwordPath. Length> 0) // if a Word instance is running, use the/w parameter to forcibly start the new instance and pass the file name as a parameter.
{WordProcess. StartInfo. FileName = winwordPath;
WordProcess. StartInfo. UseShellExecute = false;
WordProcess. StartInfo. Arguments = fileName + "/w ";
}
Else // if no Word instance is running
{
WordProcess. StartInfo. FileName = fileName;
WordProcess. StartInfo. UseShellExecute = true;
}

WordProcess. Start ();
WordProcess. WaitForExit (); // the current process is waiting until the Word instance exits.
WordProcess. Close ();

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.