#include #include #include #include #include "Functions.h" TCHAR XG_AppPath[MAX_PATH]; wchar_t* XG_IniFilePath; TCHAR XG_AppFileName[100]; TCHAR XG_AppName[100]; TCHAR XG_GlobalPath[MAX_PATH]; TCHAR XG_AppLaunchPath[MAX_PATH]; wchar_t* XG_AppLaunch; //------------------------------------------------------------------------------------------ // // Initialisation des variables, lecture du .ini (qui doit se trouver avec le .exe) // //------------------------------------------------------------------------------------------ void InitApp () { GetCurrentDirectory(sizeof(XG_AppPath), XG_AppPath); TCHAR *c = XG_GlobalPath + GetCurrentDirectory(sizeof(XG_GlobalPath), XG_GlobalPath); while(*c != '\\') c--; *c = 0; XG_IniFilePath = wcscat(XG_AppPath, TEXT("\\AppCheck.ini")); GetPrivateProfileString(TEXT("NetFramework"),TEXT("XG_fileName"),TEXT("Erreur : vérifiez le fichier ini"),XG_AppFileName,100,XG_IniFilePath); GetPrivateProfileString(TEXT("NetFramework"),TEXT("XG_AppName"),TEXT("Erreur : vérifiez le fichier ini"),XG_AppName,100,XG_IniFilePath); GetPrivateProfileString(TEXT("AppToLaunch"),TEXT("XG_AppLaunchPath"),TEXT("Erreur : vérifiez le fichier ini"),XG_AppLaunchPath,100,XG_IniFilePath); XG_AppLaunch = _tcscat(XG_GlobalPath, XG_AppLaunchPath); GetCurrentDirectory(sizeof(XG_AppPath), XG_AppPath); } //------------------------------------------------------------------------------------------ // // Fonction principale // //------------------------------------------------------------------------------------------ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { HKEY X_Key; SHELLEXECUTEINFO X_InstallThread; InitApp(); //Appel de la proc d'initialisation //Ouverture de la base de registre (X_Key contient en gros HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\uninstall if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\uninstall"), 0, KEY_READ, &X_Key) == ERROR_SUCCESS ) { // Test si .net est installé - lecture de la base de registre - installation de framework si OK de l'utilisateur // QueryKey va lire les sous clées de registre (ce qu'il y a dans X_Key que l'on vient d'ouvrir) // QueryKey renvoie true si XG_AppName existe dans la base // XG_AppName se trouve dans le .ini, c'est le nom exact de .net framework dans windows if (!QueryKey(X_Key, XG_AppName)) { if (MessageBox(NULL, TEXT("Microsoft .NET Framework n'est pas installé sur votre ordinateur.\nCet outil est nécessaire pour lancer l'utilitaire de recherche automatique de vos drivers.\n\nSouhaitez vous installer .NET Framework? Si vous choisissez non, le programme se fermera."), TEXT("Question"), MB_YESNO | MB_ICONQUESTION)==IDYES) { ZeroMemory(&X_InstallThread, sizeof(SHELLEXECUTEINFO)); X_InstallThread.cbSize = sizeof(SHELLEXECUTEINFO ); X_InstallThread.lpFile = wcscat(XG_AppPath, XG_AppFileName); // chemin complet du setup de .net Framework X_InstallThread.fMask = SEE_MASK_NOCLOSEPROCESS; X_InstallThread.lpVerb = TEXT("open"); X_InstallThread.nShow = SW_SHOWNORMAL; // Lancement de l'installation, on attend la fin du process avant de reprendre le programme if(ShellExecuteEx(&X_InstallThread)) { WaitForSingleObject(X_InstallThread.hProcess, INFINITE); } //::CloseHandle(X_InstallThread.hProcess); } else { return 0; } } //Ouverture du programme tiers à la fin du programme(dans le fichier ini) ShellExecute(NULL, TEXT("open"), XG_AppLaunch, NULL, NULL, SW_SHOWDEFAULT); } return 0 ; }