Public static void StartProgram (string directory, string fileName) {Process mainprocess = new Process (); mainprocess. startInfo. workingDirectory = directory; mainprocess. startInfo. fileName = fileName; // you do not need to specify the above directory. Here, you can write directory + filename as mainprocess. startInfo. arguments = "OK"; // You can pass the mainprocess parameter to other processes (exe files. startInfo. windowStyle = ProcessWindowStyle. normal; mainprocess. start () ;}// another process static Class Program {static void Main (string [] arguments) {string arg = arguments [0]; // arg = "OK ";}}
Start Process
// The process of killing cannot be followed by processname.exe. Remember !!! Public static void KillProcess (string processName) {Process myproc = new Process (); try {foreach (Process proc in Process. GetProcessesByName (processName) {if (! Proc. CloseMainWindow () {proc. Kill () ;}} catch (Exception ex) {throw ex ;}}
Kill Process
Private void PrintDoc () {// defines a process instance System. diagnostics. process myProcess = new System. diagnostics. process (); try {// set the Process parameter string myDocumentsPath = Environment. getFolderPath (Environment. specialFolder. personal); myProcess. startInfo. fileName = myDocumentsPath + "\ TxtForTest.txt"; myProcess. startInfo. verb = "Print"; // display all the predicates foreach (string v in myProcess. startInfo. verbs) MessageBox. show (v); myProcess. startInfo. createNoWindow = true; // start the process myProcess. start ();} catch (Win32Exception e) {if (e. nativeErrorCode = ERROR_FILE_NOT_FOUND) {MessageBox. show (e. message + "Check the path. "+ myProcess. startInfo. fileName);} else if (e. nativeErrorCode = ERROR_ACCESS_DENIED) {MessageBox. show (e. message + "You do not have permission to print this file. ");}}}
Print Document
// Start the browser: Process. start ("IExplore.exe"); // open the browser and jump to the specified URL: Process. start ("IExplore.exe", "http://www.cnblogs.com/ddhj/"); If Start is a folder path rather than a file path, this folder is opened: string myFavoritesPath = System. environment. getFolderPath (Environment. specialFolder. favorites); // obtain the "Favorites" file path // start the process System. diagnostics. process. start (myFavoritesPath );
Open the folder:
System. Diagnostics. Process. Start (FilePath );
Open a file in the folder:
System. Diagnostics. Process. Start (FilePath + "/" + FileName );
Open the folder and select a single file:
System. Diagnostics. Process. Start ("Explorer", "/select," + FilePath + "\" + FileName );
Or
System. Diagnostics. Process. Start ("assumer.exe", "/select," + FilePath + "\" + FileName );
Open the file with IE:
System. Diagnostics. Process. Start ("Explorer", FilePath + "\" + FileName );
System. Diagnostics. Process. Start ("assumer.exe", FilePath + "\" + FileName );
Note: (explorer,explorer.exe, select, case-insensitive, "/selecet," where "/," cannot be small, FilePath is the file path does not contain the file name)
Open the folder and select the webpage
System. Diagnostics. Process. Start ("assumer.exe", "http://www.sunwale.com/");