The C # Process.Start () method is detailed

Source: Internet
Author: User

System.Diagnostics.Process.Start (); What can we do? It mainly has the following functions:

1. Open a link URL (pop-up window).

2. Locate and open a file directory.

3, open the System special folder, such as "Control Panel" and so on.

So how does it accomplish these functions? Before we talk about the application, let's take a look at the construction method of Process.star ().

Name Description
Process.Start () starts (or reuses) the process resource specified by the StartInfo property of this process component and

associated with the component.
Process.Start (ProcessStartInfo) starts the message that contains the process startup information (for example, the process to start

Name), and associate the resource with the new process component with the specified process resource.
Process.Start (String) starts a process resource by specifying the name of the document or application file, and the resource

Associated with the new Process component.
Process.Start (String, string) starts a process resource by specifying the name of the application and a set of command-line arguments

and associates the resource with the new Process component.
Process.Start (String, String, SecureString, String) by specifying the application name, user name, password

and domain to start a process resource and associate the resource with the new process component.
Process.Start (String, String, String, SecureString, String) by specifying the name of the application and a

Group command line arguments, user names, passwords, and domains to start a process resource and associate the resource with the new process component

To.


(1) Publicbool Start ()

System.Diagnostics.Process Process = new System.Diagnostics.Process ();

Process.   Startinfo.filename = "Iexplore.exe"; IE browser, can be replaced

Process. startinfo.arguments = "http://www.baidu.com";

Process. Start ();
(2) Publicstaticprocessstart (Processstartinfostartinfo)

System.Diagnostics.ProcessStartInfo ProcessStartInfo = new

System.Diagnostics.ProcessStartInfo ();

Processstartinfo.filename = "Explorer.exe"; Explorer

Processstartinfo.arguments = @ "D:\";

System.Diagnostics.Process.Start (ProcessStartInfo);
(3) Publicstaticprocessstart (stringfilename)

System.Diagnostics.Process.Start (@ "D:\Program files\tencent\qq\bin\qq.exe"); Direct

Call Open File


(4) Process.Start (Stringfilename, stringarguments)

System.Diagnostics.Process.Start ("Explorer.exe", "D:\\readme.txt"); Open file directly

Readme.txt
The example above already uses Process.Start () to open the Web site method, now talk about using Processs.star () to navigate to a file

Method.

This positioning method is similar to the search target on the shortcut://explorer/select, "D:\Program files\tencent

\qq\bin\qq.exe "

String path = @ "D:\Program Files\tencent\qq\bin\qq.exe";

System.Diagnostics.Process.Start ("Explorer.exe", "/select," +path); Positioning Open D:\Program

Files\tencent\qq\bin file directory and selected QQ.exe

Note: There is a comma (,) after the/select.


And then, by calling Rundll32.exe to open some system-specific files, let's briefly introduce the functions of the Rundll32.exe

and function.

As the name implies, Rundll32 is the "execute 32-bit DLL file", which is the execution of internal functions in the DLL file, you can use the command line

The form of a windows32-bit dynamic-link library is called.

Similarly, Rundll.exe is "executing a 16-bit DLL file" and invoking a 16-bit dynamic-link library. We pass

rundll32.exe executes instructions to accomplish some functions.
As an example:

System.Diagnostics.Process.Start ("Rundll32.exe", "user.exe,restartwindows"); System restart

Command
rundll32 Command Daquan
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 panel.

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 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 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 @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 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


Command column: rundll32.exe shell32.dll,Control_RunDLL firewall.cpl
Features: Display the Windows Firewall panel

Command column: rundll32.exe shell32.dll,Control_RunDLL NETSETUP.CPL,@0,WNSW
Features: Display the wireless network settings panel

More commands please download here: http://download.csdn.net/detail/czw2010/4530206

System.Diagnostics.Process.Start ("notepad.exe"); --Open Notepad

System.Diagnostics.Process.Start ("Calc.exe"); --Open Calculator

System.Diagnostics.Process.Start ("Regedit.exe"); --Open the registration form

System.Diagnostics.Process.Start ("MSPaint.exe"); --Open drawing board

System.Diagnostics.Process.Start ("Write.exe"); --Open WordPad

System.Diagnostics.Process.Start ("Mplayer2.exe"); --Open player

System.Diagnostics.Process.Start ("Taskmgr.exe"); --Open Task Manager

System.Diagnostics.Process.Start ("Eventvwr.exe"); --Open Event Viewer

System.Diagnostics.Process.Start ("Winmsd.exe"); --Open System Information

System.Diagnostics.Process.Start ("Winver.exe"); --Open wind

System.Diagnostics.Process.Start ("Regedit.exe"); --Open the registration form

System.Diagnostics.Process.Start ("MSPaint.exe"); --Open drawing board

System.Diagnostics.Process.Start ("Write.exe"); --Open WordPad

System.Diagnostics.Process.Start ("Mplayer2.exe"); --Open player

System.Diagnostics.Process.Start ("Taskmgr.exe"); --Open Task Manager

System.Diagnostics.Process.Start ("Eventvwr.exe"); --Open Event Viewer

System.Diagnostics.Process.Start ("Winmsd.exe"); --Open System Information

System.Diagnostics.Process.Start ("Winver.exe"); --Open Windows version information

System.Diagnostics.Process.Start ("mailto:" + address); --E-mail

Shutdown.exe:

Parameter:-S shutdown-R Restart-F Force-t time-a cancel shutdown-L logoff-I display user interface

System.Diagnostics.Process.Start ("Shutdown.exe", "-r"); --Shut down and restart the computer

System.Diagnostics.Process.Start ("Shutdown.exe", "-s-f"); --Shut down the computer

System.Diagnostics.Process.Start ("Shutdown.exe", "-s-f 30"); --Turn off the computer after 30s

System.Diagnostics.Process.Start ("Shutdown.exe", "-l"); --Log off the computer

System.Diagnostics.Process.Start ("Winver.exe"); --Open Windows version information

System.Diagnostics.Process.Start ("mailto:" + address); --E-mail

Shutdown.exe:

Parameter:-S shutdown-R Restart-F Force-t time-a cancel shutdown-L logoff-I display user interface

System.Diagnostics.Process.Start ("Shutdown.exe", "-r"); --Shut down and restart the computer

System.Diagnostics.Process.Start ("Shutdown.exe", "-s-f"); --Shut down the computer

System.Diagnostics.Process.Start ("Shutdown.exe", "-s-f 30"); --Turn off the computer after 30s

System.Diagnostics.Process.Start ("Shutdown.exe", "-l"); --Log off the computer

System.Diagnostics.Process.Start ("Shutdown.exe", "-a"); --undo shut down the computer

SpecialFolder Enumeration Members:

Member name Description
The ApplicationData directory, which serves as the common repository for application-specific data for the current roaming user.

Roaming users work on more than one computer on the network. The roaming user's profile is saved on a network server when the user logs on

To a system, it is loaded into the system.
The Commonapplicationdata directory, which serves as a common repository for application-specific data that is used by all users.
CommonProgramFiles the directory for components that are shared among applications.
Cookies are used as directories for public repositories of Internet cookies.
Desktop logical desktops, not physical file system locations.
The desktopdirectory is used to physically store the directory of File objects on the desktop.

This directory should not be confused with the Desktop folder itself, which is a virtual folder.
Favorites a directory that serves as a common repository for user favorite items.
History the directory that is used as the public repository for Internet Chronicle items.
Internetcache is used as a directory for public repositories of temporary Internet files.
Localapplicationdata directory, which is used as the common storage for application-specific data that is not currently used by roaming users

Store.
MyComputer the "My Computer" folder.
Attention

Because the path is not defined for the My Computer folder, the MyComputer constant will always generate an empty string ("").
MyDocuments the "My Computer" folder.
MyMusic the "My Music" folder.
MyPictures the "My Pictures" folder.
Personal the directory that is used as a common repository for documents.
ProgramFiles the "Program Files" directory.
Programs contains a directory of user program groups.
Recent The directory that contains the documents that the user has recently used.
SendTo the directory containing the Send menu item.
StartMenu the directory containing the Start menu item.
Startup directory that corresponds to the user's startup program group.

These programs are started every time a user logs on, starts Windows NT or later, or starts Windows 98 o'clock


System "System" directory.
Templates a directory that is used as a common repository for document templates.

Through Environment.getfolderpath (Environment.SpecialFolder.XXXXX), we can easily get the department

And then use the Process.Start () method to open the folder.

For example:

System.Diagnostics.Process.Start (Environment.getfolderpath

(Environment.SpecialFolder.System)); Open System Folder (System32 folder)

[System.Runtime.InteropServices.DllImportAttribute ("User32.dll")]
private static extern int FindWindow (string ClassName, string windowname);

[System.Runtime.InteropServices.DllImport ("User32.dll")]
private static extern int ShowWindow (int handle, int cmdshow);

[System.Runtime.InteropServices.DllImport ("Winmm.dll", EntryPoint = "mciSendString",

CharSet = System.Runtime.InteropServices.CharSet.Auto)]
private static extern int mcisendstring (string lpstrcommand, String lpstrreturnstring,

int ureturnlength, int hwndcallback);

Private Const int sw_hide = 0;//API parameter indicates hidden window
Private Const int sw_show = 5;//API parameter indicates that the window is displayed with the current size and position

ShowWindow (FindWindow ("Shell_traywnd", null), sw_hide); --Hide hidden taskbar

ShowWindow (FindWindow ("Shell_traywnd", null), sw_show); --Show taskbar

mciSendString ("Set CDAudio door open", NULL, 127, 0); --Eject Optical drive

mciSendString ("Set CDAudio door closed", NULL, 127, 0); --Close Optical drive
This article reprinted from: Http://blog.csdn.net/chen_zw/article/details/7896264 (bo master: Mirrors)

The C # Process.Start () method is detailed

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.