long RegistryRW::DeleteKey(const std::string& path,const std::string& subKey) const { HKEY key; long ret = OpenRegKey(path,key); if (ret!=ERROR_SUCCESS) return ret; #ifdef _WIN32 ret =RegDeleteKeyEx(key, subKey.c_str(), KEY_WOW64_32KEY, 0); #else ret= RegDeleteKeyEx(key, subKey.c_str(), KEY_WOW64_64KEY, 0); #endif return ret; }
bool RegUtil::DeleteRegKey(HKEY hPreDefined, const TCHAR * keyName, BOOL bForceNative /* = FALSE */) { HKEY hKey = NULL; REGSAM samDesired = KEY_WRITE; if(is64BitOS()) { if(bForceNative) samDesired |= KEY_WOW64_64KEY; } long cError = RegOpenKeyEx(hPreDefined, keyName, 0, samDesired, &hKey); if (cError != ERROR_SUCCESS) // Return if it doesn't exist return true; if(cError == ERROR_SUCCESS) { cError = RegDeleteKeyEx(hPreDefined, keyName, samDesired, 0); RegCloseKey(hKey); if(cError==ERROR_SUCCESS) return true; } return false; }
HRESULT deleteKey( HKEY root, const WCHAR* subKey, const WCHAR* delKey ) { HRESULT hr; HKEY hkSubKey = NULL; HKEY hkNewKey = NULL; if( subKey != NULL ) { hr = RegOpenKeyEx( root, subKey, 0, KEY_WRITE, &hkSubKey ); if( hr != ERROR_SUCCESS ) { return hr; } } else { hkSubKey = root; } hr = RegDeleteKeyEx( hkSubKey, delKey, KEY_WOW64_32KEY, NULL ); if( hkSubKey != root) RegCloseKey( hkSubKey ); return hr; }
void Registry::DeleteSubKey(JNIEnv* env, jobject /*self*/, jlong handle, jstring subKey) { const char* sk = subKey ? env->GetStringUTFChars(subKey, 0) : 0; if(handle != 0 && sk != 0) #ifdef X64 RegDeleteKeyEx((HKEY) handle, sk, KEY_WOW64_64KEY, 0); #else RegDeleteKey((HKEY) handle, sk); #endif if(sk) env->ReleaseStringUTFChars(subKey, sk); }
bool FRegistryRootedKey::Write(bool bRemoveDifferences) const { bool bRes = false; if (Key) { bRes = Key->Write(hRootKey, Path, bRemoveDifferences); } else { bRes = (!Exists() || RegDeleteKeyEx(hRootKey, *Path, 0, 0) == ERROR_SUCCESS); } return bRes; }
int RegisterUnregisterVPinMAME(HWND hWnd, int fRegister) { HRESULT hr; HMODULE hModule; // so now let's see if we can load vpinmame.dll hModule = LoadLibrary("vpinmame.dll"); if ( !hModule ) { DisplayError(hWnd, GetLastError(), "The 'vpinmame.dll' file can't be loaded.", "Be sure to have this file in the current directory!"); return 0; } char szModuleFilename[MAX_PATH]; GetModuleFileName(hModule, szModuleFilename, sizeof szModuleFilename); char szVersion[256]; GetVersionResourceEntry(szModuleFilename, TEXT("ProductVersion"), szVersion, sizeof szVersion); char szMsg[256]; if ( fRegister ) wsprintf(szMsg, "You have selected to install version %s of Visual PinMAME! \nAre you ready to proceed?", szVersion); else wsprintf(szMsg, "You have selected to uninstall version %s of Visual PinMAME! \nAre you ready to proceed?", szVersion); if ( MessageBox(hWnd, szMsg, g_szCaption, MB_ICONQUESTION|MB_YESNO)==IDNO ) { if ( fRegister ) MessageBox(hWnd, "Installation aborted!", g_szCaption, MB_ICONEXCLAMATION|MB_OK); else MessageBox(hWnd, "UnInstallation aborted!\nVisual PinMAME is still installed on your system", g_szCaption, MB_ICONEXCLAMATION|MB_OK); FreeLibrary(hModule); return 0; } if ( fRegister ) { typedef HRESULT DLLREGISTERSERVER(void); DLLREGISTERSERVER* DllRegisterServer = (DLLREGISTERSERVER*) GetProcAddress(hModule, "DllRegisterServer"); if ( !DllRegisterServer ) { DisplayError(hWnd, GetLastError(), "Can't find the registering function (DllRegisterServer) in the vpinmame.dll.", "Please check if you have a valid vpinmame.dll!"); FreeLibrary(hModule); return 0; } hr = (*DllRegisterServer)(); if ( FAILED(hr) ) { DisplayError(hWnd, hr, "Unable to register the class object!", "Please check if you have a valid vpinmame.dll!"); FreeLibrary(hModule); return 0; } FreeLibrary(hModule); // load the class one time to check if it's working IUnknown *pUnknown; CLSID ClsID; hr = CLSIDFromProgID(OLESTR("VPinMAME.Controller"), &ClsID); if ( FAILED(hr) ) { DisplayError(hWnd, hr, "Class couldn't be found. Registering failed"); return 0; } hr = CoCreateInstance(ClsID, NULL, CLSCTX_INPROC_SERVER, IID_IUnknown, (void**) &pUnknown); if ( FAILED(hr) ) { DisplayError(hWnd, hr, "Can't create the Controller class"); return 0; } pUnknown->Release(); } else { typedef HRESULT DLLUNREGISTERSERVER(void); DLLUNREGISTERSERVER* DllUnregisterServer = (DLLUNREGISTERSERVER*) GetProcAddress(hModule, "DllUnregisterServer"); if ( !DllUnregisterServer ) { DisplayError(hWnd, GetLastError(), "Can't find the unregistering function (DllUnegisterServer) in the vpinmame.dll.", "Please check if you have a valid vpinmame.dll!"); FreeLibrary(hModule); return 0; } hr = (*DllUnregisterServer)(); if ( FAILED(hr) ) { DisplayError(hWnd, hr, "Unable to unregister the class object!", "Please check if you have a valid vpinmame.dll!"); FreeLibrary(hModule); return 0; } FreeLibrary(hModule); } if ( !fRegister ) { if ( MessageBox(hWnd, "Do you want also delete all registry entrys Visual PinMAME has made?", g_szCaption, MB_ICONQUESTION|MB_YESNO)==IDYES ) RegDeleteKeyEx(HKEY_CURRENT_USER, "Software\\Freeware\\Visual PinMame"); } return 1; }
bool CRegEdit::DeleteKey(HKEY hKey, LPCTSTR szSubKey,bool bWin32) { int nRet = RegDeleteKeyEx(hKey, szSubKey,(bWin32)?KEY_WOW64_32KEY:KEY_WOW64_64KEY, 0); return ERROR_FILE_NOT_FOUND == nRet || nRet == ERROR_SUCCESS; }