Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***********************************
- NOTE: All app and variable names are
- changed.
- ------------------------------------
- Included files: iostream, string,
- winreg.h (through windows.h)
- IDE: Visual C++ 2008 Express
- ***********************************/
- /***********************************
- The data structure that can be seen
- below looks like this:
- struct apps
- {
- string installPath;
- string exePath;
- string iniPath;
- };
- ***********************************/
- #define BUFFER 8192
- void getApps()
- {
- char ValueBuffer[255];
- HKEY hKey;
- DWORD BufferSize = BUFFER;
- if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\AppVendor\\APPKEY1", 0, KEY_READ, &hKey) == ERROR_SUCCESS) //This one succeeds
- {
- RegGetValue(hKey, NULL, "PATH", RRF_RT_ANY, NULL, (PVOID)&ValueBuffer, &BufferSize);
- cout << "1: Application 1" << endl;
- string bufferConvert(ValueBuffer);
- app1.installPath = bufferConvert;
- app1.exePath = app1.installPath + "app1.exe";
- app1.iniPath = app1.installPath + "app1.ini";
- memset(ValueBuffer, '\0', 255 );
- }
- else
- {
- cerr << "ERROR opening APPKEY1" << endl; //
- }
- RegCloseKey(hKey);
- if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\AppVendor\\APPKEY2", 0, KEY_READ, &hKey) == ERROR_SUCCESS) //Strangely, this key opens...
- {
- RegGetValue(hKey, NULL, "PATH", RRF_RT_ANY, NULL, (PVOID)&ValueBuffer, &BufferSize); //...But this function fails (Error 234: ERROR_MORE_DATA, according to MSDN)
- string bufferConvert(ValueBuffer);
- app2.installPath = bufferConvert;
- memset(ValueBuffer, '\0', 255 );
- //This "if...else if" structure is there because there are two mutually exclusive versions of the app
- RegGetValue(hKey, NULL, "EXEFILE", RRF_RT_ANY, NULL, (PVOID)&ValueBuffer, &BufferSize); //This one also fails
- if(ValueBuffer == "app2verA.exe")
- {
- cout << "2: Application 2 Version A" << endl;
- app2.exePath = app2.installPath + "app2verA.exe";
- app2.iniPath = app2.installPath + "app2verA.ini";
- }
- else if(ValueBuffer == "app2verB.exe")
- {
- cout << "2: Application 2 Version B" << endl;
- app2.exePath = app2.installPath + "app2verB.exe";
- app2.iniPath = app2.installPath + "app2verB.ini";
- }
- memset(ValueBuffer, '\0', 255 );
- }
- else
- {
- cerr << "ERROR opening APPKEY2" << endl;
- }
- RegCloseKey(hKey);
- if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\AppVendor\\APPKEY3", 0, KEY_READ, &hKey) == ERROR_SUCCESS)
- {
- RegGetValue(HKEY_LOCAL_MACHINE, NULL, "PATH", RRF_RT_ANY, NULL, (PVOID)&ValueBuffer, &BufferSize); //Works, though it's the same as before
- cout << "3: Application 3" << endl;
- RegGetValue(HKEY_LOCAL_MACHINE, NULL, "PATH", NULL, NULL, &ValueBuffer, &BufferSize);
- string bufferConvert(ValueBuffer);
- app3.installPath = bufferConvert;
- app3.exePath = app3.installPath + "app3.exe";
- app3.iniPath = app3.installPath + "app3.ini";
- memset(ValueBuffer, '\0', 255 );
- }
- else
- {
- cerr << "ERROR opening APPKEY3" << endl;
- }
- RegCloseKey(hKey);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement