Use another application or command line (.exe with parameters) in csung)

Source: Internet
Author: User

In. net, system. diaglostics. process can be used to call another command line orProgram.

Using system. diagnostics;
For DoS
Process. Start ("cmd.exe ");
For other files
Process. Start ("absolute limit file name .exe ");
------------------------------------
How to call an external dos program in C?
Use the process object:
System. Diagnostics. PROCESS p = new system. Diagnostics. Process ();
P. startinfo. filename = "arj.exe"; // name of the program to be started
P. startinfo. Arguments = "-x sourcefile. arj c:/Temp"; // start Parameters
P. Start (); // start
If (P. hasexisted) // determines whether the running is completed.
P. Kill ();

Certificate -------------------------------------------------------------------------------------------------------------------------------------
/// <Summary>
/// Start other applications
/// </Summary>
/// <Param name = "file"> Application name </param>
/// <Param name = "workdirectory"> application working directory </param>
/// <Param name = "ARGs"> command line parameters </param>
/// <Param name = "style"> window style </param>
Public static bool startprocess (string file, string workdirectory, string ARGs, processwindowstyle style)
{
Try
{
Process myprocess = new process ();
Processstartinfo startinfo = new processstartinfo (file, argS );
Startinfo. windowstyle = style;
Startinfo. workingdirectory = workdirectory;
Myprocess. startinfo = startinfo;
Myprocess. startinfo. useshellexecute = false;
Myprocess. Start ();
Return true;
}
Catch (exception E0)
{
MessageBox. Show ("An error occurred while starting the application! Cause: "+ e0.message );
}
Return false;
}



String parms = "" + globalobject. getinstance (). userid + "" + globalobject. getinstance (). userpassword;
If (publicmethods. startprocess (application. startuppath + @ "/uptool/uptool.exe", application. startuppath + "// uptool", parms, processwindowstyle. Normal ))
{
Environment. Exit (0 );
}
Bytes ----------------------------------------------------------------------------------------------------------------------
Process. Start ("iexplore.exe", "http://www.newhappy.cn ");
System. Diagnostics. processstartinfo startinfo = new system. Diagnostics. processstartinfo ();
Startinfo. filename = "File Name of the EXE execution ";
Startinfo. Arguments = "parameter array ";
System. Diagnostics. process. Start (startinfo );
Bytes ----------------------------------------------------------------------------------------------------------------------------
1. When there are many times, we need to call the external exe program and wait for it to finish running before we can continue the following actions. How can we implement it? Please refer to the following Code .
'How to wait for the external program to run.
'Read files from the system folder
Dim sysfolder as string = _
Environment. getfolderpath (environment. specialfolder. System)
'Create a new process structure
Dim pinfo as new processstartinfo ()
'Sets the employee filenameas the eula.txt of the system data.
Pinfo. filename = sysfolder & "/eula.txt"
'Run the file
Dim P as process = process. Start (pinfo)
'Wait until the program is loaded
P. waitforinputidle ()
'Wait for the trip to exit
P. waitforexit ()
'Continue to execute the following code
MessageBox. Show ("continue executing code ")

2. We want to forcibly close it in five seconds, instead of manually disabling it.
'Set the exit time
Dim timeout as integer = 5000
Dim sysfolder as string = _
Environment. getfolderpath (environment. specialfolder. System)
Dim pinfo as new processstartinfo ()
Pinfo. filename = sysfolder & "/eula.txt"
Dim P as process = process. Start (pinfo)
P. waitforinputidle ()
P. waitforexit (timeout)
'Check whether it is disabled before timeout.
If P. hasexited = false then
'The route entry is still running
'Check whether the process responds.
If P. Responding then
P. closemainwindow () 'Close the window
Else
P. Kill () 'force interrupt
End if
End if
MessageBox. Show ("continue executing code ")

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.