Because the program runs in a ukey (USB flash drive) instead of a setup package, you cannot directly run the. Net EXE startup program if the framework is not installed at startup,
Solution:
Startup.exe written by cup.exe is used as the startup program. It also checks whether the framework is installed on the local machine. If not, C ++ calls start installation. After the framework is installed, it starts the C # application.
Among them, the C ++ detection and installation startup program code is as follows: VC ++ 6.0 implements a hidden form:
// Startupdlg. CPP: implementation file // # include "stdafx. H "# include" startup. H "# include" startupdlg. H "// # include" WINBASE. H "// # include" shlobj. H "// # include" shellapi. H "# include" tlhelp32.h "# ifdef _ debug # define new debug_new # UNDEF this_filestatic char this_file [] = _ file __; # endif ////////////////////////////////////// //////////////////////////////////////// /cstartupdlg dialogcstartupdlg:: cstartupd LG (cwnd * pparent/* = NULL */): cdialog (cstartupdlg: IDD, pparent) {// {afx_data_init (cstartupdlg) // note: the classwizard will add member initialization here //} afx_data_init // note that loadicon does not require a subsequent destroyicon in response = afxgetapp ()-> loadicon (idr_mainframe);} void response:: dodataexchange (cdataexchange * PDX) {cdialog: dodataexchange (PDX); // {afx_data_map (cstartupdl G) // Note: The classwizard will add DDX and DDV cballs here //} afx_data_map} locate (cstartupdlg, cdialog) // {afx_msg_map (cstartupdlg) on_wm_paint () on_wm_querydragicon () on_bn_clicked (btncheckframework, onbtncheckframework) //} afx_msg_mapend_message_map () //////////////////////////////////////// /// // cstartupdlg message handlersbool cstartupdlg:: oninitdialog () {Cdialog: oninitdialog (); // set the icon for this dialog. the framework does this automatically // when the application's main window is not a dialogseticon (m_hicon, true); // set big iconseticon (m_hicon, false ); // Set Small icononbtncheckframework (); // todo: add extra initialization herereturn true; // return true unless you set the focus to a control} // if you add a Minimize button to your Dialog, You will need the code below // to draw the icon. for MFC applications using the document/view model, // This is automatically done for you by the framework. void cstartupdlg: onpaint () {If (isiconic () {// cpaintdc DC (this); // device context for painting // sendmessage (wm_iconerasebkgnd, (wparam) DC. getsafehdc (), 0); // center icon in client rectangle // int cxicon = getsystemmetrics (sm_cxicon); // int cy Icon = getsystemmetrics (sm_cyicon); // crect rect; // getclientrect (& rect); // int x = (rect. width ()-cxicon + 1)/2; // int y = (rect. height ()-cyicon + 1)/2; // draw the icon // dc. drawicon (X, Y, m_hicon);} else {// cdialog: onpaint ();} static int I = 2; if (I> 0) {I --; showwindow (sw_hide);} else {cdialog: onpaint () ;}// the system callthis to obtain the cursor to display while the user drags // The minimized win Dow. hcursor cstartupdlg: onquerydragicon () {return (hcursor) m_hicon ;} // check the Framework Version lpstr regeditvision [] ={// "SOFTWARE \ Microsoft \ Net Framework Setup \ NDP \ V2.0 ", // "Software \ Microsoft \ Net Framework Setup \ NDP \ v2.0.50727", // "SOFTWARE \ Microsoft \ Net Framework Setup \ NDP \ V3.0 ", // "Software \ Microsoft \ Net Framework Setup \ NDP \ v3.5", "Software \ Microsoft \ Net Framework Setup \ NDP \ v4.0 "}; // check Registry bool checkframeworkregedit () {bool result = true; // judge whether the registry exists // For (INT I = 0; I <4; I ++) // {hkey CK; // registry key // check whether the registry has this key value if (error_success = regopenkeyex (HKEY_LOCAL_MACHINE, regeditvision [0], 0, key_all_access, & CK )) {regclosekey (CK); // disable registry result = true; // break;} else {result = false;} //} return result ;} // check the process (name in Task Manager) based on the program name. If no value is found, return 0. Find the return process id dword getprocessidfromname (lpctstr name) {processentr Y32 PE; DWORD id = 0; handle hsnapshot = creatw.lhelp32snapshot (th32cs_snapprocess, 0); PE. dwsize = sizeof (processentry32); If (! Process32first (hsnapshot, & PE) return 0; while (1) {PE. dwsize = sizeof (processentry32); If (process32next (hsnapshot, & PE) = false) break; If (strcmp (PE. szexefile, name) = 0) {id = PE. th32processid; break ;}} closehandle (hsnapshot); Return ID;} // detection. net Framework 4.0 is installed or not. If it is not installed, the installation package call void cstartupdlg: onbtncheckframework () {// check the registry to see if it complies with framework4.0if (checkframeworkregedit ()) {If (winexec ("xxx.exe", sw_shownormal) = error_fi Le_not_found) MessageBox ("failed to start XXX program! "," Prompt ", mb_ OK); else {// The process is suspended for 10 s to monitor the running status of XXX. If it has been disabled, the monitoring program sleep (10000) is ended ); while (getprocessidfromname ("xxx.exe")> 0) {sleep (1000);} Sleep (2000); sendmessage (wm_close );}} else {If (MessageBox ("required by the application. net Framework 4.0 installation package support. Are you sure you want to install it? "," Prompt ", mb_okcancel) = idok) {winexec (" framework/dotnetfx40_full_x86_x64.exe ", sw_shownormal); // The process hangs for 3 S and starts to monitor framework installation, after the installation is complete, start the xxx program sleep (3000); While (getprocessidfromname ("dotnetfx40_full_x86_x64.exe")> 0) {sleep (1000 );} // disable framework installation. If (checkframeworkregedit () {If (winexec ("orgcertificate.exe", sw_shownormal) = error_file_not_found) MessageBox ("failed to start XXX program! "," Prompt ", mb_ OK); else {// The process is suspended for 10 s to monitor the running status of XXX. If it has been disabled, the monitoring program sleep (10000) is ended ); while (getprocessidfromname ("xxx.exe")> 0) {sleep (1000);} Sleep (2000); sendmessage (wm_close);} else {MessageBox ("framework 4.0 Installation failed, please reinstall it! "," Prompt ", mb_ OK) ;}} sendmessage (wm_close );}}