Use C # to start another program

Source: Internet
Author: User

A piece of instance code, the purpose of the program is to useC # Start another program. The Technical Director has provided us with an effective way to start the program. Now I want to share with you:

 

 

Private void btnCreate_Click (object sender, EventArgs e)
...{
Int hWnd = FindWindow (null, "test"); // The Name Of The Window body.
// Check if PowerReuse is launched or not
// If yes, pass path of project to PowerReuse
// Or, launch PowerReuse with specified parameter
If (hWnd> 0)
...{
MessageBox. Show ("powerReuse has been launched already." + "+ hWnd. ToString ());
// SendMessage to PowerReuse
Return;
}
Try
...{
Process Main_P = new Process ();
// This path shocould be retrieved from Windows Registry,
// The loaction is written by Installter during process of installation.
Main_P.StartInfo.FileName = @ "C: est.exe"; // The exe path of the runtime.
// This URL is passed to PowerReuse to open
Main_P.StartInfo.Arguments = @ "C: Tempabc. prj"; // runtime data
Main_P.StartInfo.UseShellExecute = true;
Main_P.Start ();
//
// We have to wait for a while until UI has been initialized
//
Main_P.WaitForInputIdle (10000 );
// Although UI has been initialzied,
// It does not mean main form of application has been completed.

 


// We may wait for another 10 seconds
For (int I = 0; I <100; I ++)
...{
HWnd = FindWindow (null, "PowerReuse (Beta )");
// HWnd = main_p.main1_whandle.toint32 ();
If (hWnd> 0) break;
Thread. Sleep (100 );
}
// Here, we check if PowerReuse is fully launched
If (hWnd = 0)
...{
// Handle exception
MessageBox. Show ("We cannot find window handle of PowerReuse ");
}
Else
...{
// Other handling
//
MessageBox. Show (hWnd. ToString () + "" + main_p.main1_whandle.tostring () + "" + Main_P.MainWindowTitle );
}
}
Catch (Exception ex)
...{
MessageBox. Show (ex. Message );
}
}

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.