//--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit1.h" #include //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { DWORD size; char path[1024]; char app[1024]; DWORD type; HKEY hKey; STARTUPINFO StartupInfo; PROCESS_INFORMATION ProcessInformation; if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\sword.exe\\", NULL, KEY_READ, &hKey) == ERROR_SUCCESS) { // if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\sword.Exe", NULL, KEY_READ, &hKey) == ERROR_SUCCESS) { RegQueryValueEx(hKey, "Path", NULL, &type, path, &size); strcpy(app, path); strcat(app, "\\InstallMgr"); //SetCurrentDirectory(path); GetStartupInfo(&StartupInfo); CreateProcess( NULL, // pointer to name of executable module app, // pointer to command line string NULL, // pointer to process security attributes NULL, // pointer to thread security attributes TRUE, // handle inheritance flag NORMAL_PRIORITY_CLASS, // creation flags NULL, // pointer to new environment block path, // pointer to current directory name &StartupInfo, // pointer to STARTUPINFO &ProcessInformation // pointer to PROCESS_INFORMATION ); RegCloseKey(hKey); } } //--------------------------------------------------------------------------- void __fastcall TForm1::Button2Click(TObject *Sender) { DWORD size; char *path; char *app; DWORD type; HKEY hKey; STARTUPINFO StartupInfo; PROCESS_INFORMATION ProcessInformation; DWORD ExitCode; if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\sword.exe\\", NULL, KEY_READ, &hKey) == ERROR_SUCCESS) { RegQueryValueEx(hKey, "Path", NULL, &type, NULL, &size); path = (char *) calloc(size+1, 1); app = (char *) calloc(size+40, 1); RegQueryValueEx(hKey, "Path", NULL, &type, path, &size); strcpy(app, path); strcat(app, "\\InstallMgr -uninstall"); GetStartupInfo(&StartupInfo); if (CreateProcess(NULL, "app", NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, path, &StartupInfo, &ProcessInformation)) { // CreateProcess(NULL, app, NULL, NULL, TRUE, DEBUG_PROCESSNORMAL_PRIORITY_CLASS, NULL, path, &StartupInfo, &ProcessInformation); do { _sleep(1); GetExitCodeProcess(ProcessInformation.hProcess, &ExitCode); } while (ExitCode == STILL_ACTIVE); free(app); free(path); RegCloseKey(hKey); } else { LPVOID lpMsgBuf; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language (LPTSTR) &lpMsgBuf, 0, NULL ); // Display the string. MessageBox( NULL, (const char *)lpMsgBuf, "GetLastError", MB_OK|MB_ICONINFORMATION ); // Free the buffer. LocalFree( lpMsgBuf ); } } } //---------------------------------------------------------------------------