C ++ checks the. NET version in the registry, automatically installs the. NET installation package, and then runs the C # program.

Source: Internet
Author: User

To be honest, my c ++ skills are too weak, so I hope that people will not joke.

Do thisArticleMainly to solveSkydiaThis problem
The system automatically determines whether there is a. NET Framework. If not, install the. NET Framework!

Let's not talk about it.CodeRight!
There are still many comments in the Code. If you still have any questions, please refer to the comments below.

Code

  # Include  <  Stdio. h  >  
# Include < Windows. h >
# Include < Iostream >

Using Namespace STD;

Int Checkreg ()
{
Lpstr regeditstr = " Software \ Microsoft \ Net Framework Setup \ NDP \ v3.5 " ; // Now we can determine if it is 3.5, but we are not sure if it is 3.5 SP1.
Hkey CK; // Registry Key
If (Error_success = Regopenkeyex (HKEY_LOCAL_MACHINE, regeditstr, 0 , Key_all_access, & CK )) // Check whether this key value exists in the registry.
{
Regclosekey (CK ); // Disable Registry
Cout < " He installed. net3.5 in his system. You can run your installation package. " < Endl;
Return 1 ;
}
Else
{
Cout < " He hasn't installed. net3.5 in his system. Now start to install it! " < Endl;
Return 0 ;
}
}

Int Startexe (lpstr path)
{
Startupinfo stinfo; // When a new process is created, the relevant members of the structure will be used.
Zeromemory (( Void * ) & Stinfo, Sizeof (Startupinfo )); // Leave stinfo empty
Process_information processinfo; // Data Structure of Process Information
Stinfo. CB = Sizeof (Startupinfo ); // Number of bytes in the startupinfo Structure
Stinfo. dwflags = Startf_useshowwindow; // Display window
Stinfo. wshowwindow = Sw_show; // This applicationProgramHow should the first overlapping window appear?
If ( ! CreateProcess (path, path, null, null, False , 0 , Null, null, & Stinfo, & Processinfo ))
{
// DWORD dwret = getlasterror (); // Startup failed to obtain abnormal values
Return 0 ;
}
Else
{
Waitforsingleobject (processinfo. hprocess, infinite ); // Wait until the installation is complete. This method is blocking!
Return 1 ;
}
}

Int Startcheck ()
{
Lpstr snetfile = " C: \ Program Files \ netmeeting \ conf.exe " ; // Path of your. net installation package
Lpstr sexefile = " C: \ Program Files \ google pinyin 2 \ googlepinyinsettingwizard.exe " ; // Path of your program
If (Checkreg ())
{
Startexe (sexefile );
Cout < " Installation Complete " < Endl;
}
Else
{
Startexe (snetfile );
Startcheck ();
}
Return 1 ;
}

Int Main ( Void )
{
Startcheck ();
Char A;
CIN > A;
Return 0 ;
}

 

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.