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 ;
}