in src/main/cpp/jnilib/windows/src/jni_WindowsRegistry.c [293:331]
JNIEXPORT void JNICALL Java_org_netbeans_installer_utils_system_windows_WindowsRegistry_deleteKey0(JNIEnv *jEnv, jobject jObject, jint jMode, jint jSection, jstring jParent, jstring jChild) {
HKEY hkey = 0;
unsigned short* jParentS = getWideChars(jEnv, jParent);
unsigned short* jChildS = getWideChars(jEnv, jChild);
if (RegOpenKeyExW(getHKEY(jSection), jParentS, 0, KEY_READ | KEY_WRITE | getMode(jMode), &hkey) == ERROR_SUCCESS) {
LONG mode = getMode(jMode);
if(mode==0) {
if (RegDeleteKeyW(hkey, jChildS) != ERROR_SUCCESS) {
throwException(jEnv, "Could not delete key");
}
} else {
typedef LONG (WINAPI *LPFN_REGDELETEKEYEXW) (HKEY, LPCWSTR, REGSAM, DWORD);
LPFN_REGDELETEKEYEXW regDeleteKeyExW;
HMODULE hModule = GetModuleHandle(TEXT("advapi32.dll"));
if(hModule == NULL) {
hModule = LoadLibraryA("advapi32.dll");
}
regDeleteKeyExW = (LPFN_REGDELETEKEYEXW) GetProcAddress(hModule,"RegDeleteKeyExW");
if (NULL != regDeleteKeyExW) {
if (regDeleteKeyExW(hkey, jChildS, mode, 0) != ERROR_SUCCESS) {
throwException(jEnv, "Could not delete key");
}
} else {
throwException(jEnv, "Cannot load function RegDeleteKeyExW");
}
}
} else {
throwException(jEnv, "Could not open the parent key");
}
if (hkey != 0) {
RegCloseKey(hkey);
}
FREE(jParentS);
FREE(jChildS);
}