/* * Use arg->key to get user preference, if no user preference use arg key and value to create entry */ void getJvmUserArg(TCHAR* appid, JVMUserArg *arg) { HKEY hKey = 0; DWORD dwType, dwCount = MAX_VALUE_LENGTH * sizeof (TCHAR); TCHAR userValue[MAX_VALUE_LENGTH] = {0}; LONG success = createRegKey(appid, &hKey); if (success == ERROR_SUCCESS) { TCHAR* regOptionName = convertKeyToWinReg(arg->name); if (regOptionName != NULL) { success = RegQueryValueEx(hKey, regOptionName, NULL, &dwType, (LPBYTE) userValue, &dwCount); if (success == ERROR_SUCCESS) { TCHAR *regValueName = convertWinRegToJava(userValue); if (regValueName != NULL) { arg->value = wcsdup(regValueName); //Don't free regValueName arg->value requires malloc'ed pointer } } else if (success == ERROR_FILE_NOT_FOUND) { TCHAR *regValueName = convertKeyToWinReg(arg->value); if (regValueName != NULL) { success = RegSetValueEx(hKey, regOptionName, NULL, REG_SZ, (LPBYTE) regValueName, (wcslen(regValueName)+1)*sizeof(TCHAR)); free(regValueName); } } free(regOptionName); } RegCloseKey(hKey); } }
bool RegistryHandler::setupLoggingEntries(const char* regKeyName) { bool setup = false; HKEY hKey = createRegKey(regKeyName); if (hKey != NULL) { // get the [expandable] path location of this executable filename char filePath[MAX_PATH]; GetModuleFileName(NULL, filePath, sizeof(filePath)); // Store the Event ID message-file name under the 'EventMessageFile' subkey // and the flag mask indicating the supported event logging types setup = storeRegValueExpString(hKey, REG_KEY_EVENT_MESSAGE_FILE, filePath) && storeRegValueDword(hKey, REG_KEY_EVENT_TYPES_SUPPORTED, EVENT_LOG_TYPES); RegCloseKey(hKey); } return setup; }
bool RegistryHandler::writeServiceParams(const ServiceParameters& serviceParams) { bool written = true; // set to false if any operations fail // Create an entry in the registry for this service's parameters. HKEY hKey = createRegKey(serviceKeyName); if (hKey == NULL) { written = false; // failed at the first step ServiceLogger::write("Failed to create registry key to write service parameters\n"); } // Store the software version number, for future interrogation if required if (written && !storeRegValueString(hKey, REG_KEY_SW_VERSION, STRPRODUCTVER)) { written = false; } // Set the JVM Library value. if (written && !storeRegValueString(hKey, REG_KEY_JVM_LIBRARY, serviceParams.getJvmLibrary())) { written = false; } // Set the jvm option count. if (written && !storeRegValueDword(hKey, REG_KEY_JVM_OPTION_COUNT, serviceParams.getJvmOptionCount())) { written = false; } // Set the jvm options. for (int opt = 0; written && (opt < serviceParams.getJvmOptionCount()); opt++) { char optKeyName[256]; sprintf(optKeyName, REG_KEY_JVM_OPTION_NO_FMT, opt); written = storeRegValueString(hKey, optKeyName, serviceParams.getJvmOption(opt)); } // Set the start class. if (written && !storeRegValueString(hKey, REG_KEY_START_CLASS, serviceParams.getStartClass())) { written = false; } // Set the start method. if (written && !storeRegValueString(hKey, REG_KEY_START_METHOD, serviceParams.getStartMethod())) { written = false; } // Set the start parameter count. if (written && !storeRegValueDword(hKey, REG_KEY_START_PARAM_COUNT, serviceParams.getStartParamCount())) { written = false; } // Set the start parameters. for (int param = 0; written && (param < serviceParams.getStartParamCount()); param++) { char paramKeyName[256]; sprintf(paramKeyName, REG_KEY_START_PARAM_NO_FMT, param); written = storeRegValueString(hKey, paramKeyName, serviceParams.getStartParam(param)); } // Set stop class/method/parameters if (written && (serviceParams.getStopClass() != NULL)) { // Set the stop class. if (written && !storeRegValueString(hKey, REG_KEY_STOP_CLASS, serviceParams.getStopClass())) { written = false; } // Set the stop method. if (written && !storeRegValueString(hKey, REG_KEY_STOP_METHOD, serviceParams.getStopMethod())) { written = false; } // Set the stop parameter count. if (written && !storeRegValueDword(hKey, REG_KEY_STOP_PARAM_COUNT, serviceParams.getStopParamCount())) { written = false; } // Set the stop parameters. for (int param = 0; written && (param < serviceParams.getStopParamCount()); param++) { char paramKeyName[256]; sprintf(paramKeyName, REG_KEY_STOP_PARAM_NO_FMT, param); written = storeRegValueString(hKey, paramKeyName, serviceParams.getStopParam(param)); } } // Set the out file, if specified if (written && !storeRegValueString(hKey, REG_KEY_SYSTEM_OUT, serviceParams.getOutFile())) { written = false; } // Set the err file, if specified if (written && !storeRegValueString(hKey, REG_KEY_SYSTEM_ERR, serviceParams.getErrFile())) { written = false; } // Set the current directory, if specified if (written && !storeRegValueString(hKey, REG_KEY_CURRENT_DIR, serviceParams.getCurrentDirectory())) { written = false; } // Set the path extension, if specified if (written && !storeRegValueString(hKey, REG_KEY_PATH_EXT, serviceParams.getPathExt())) { written = false; } // Set the shutdown timeout if (written && !storeRegValueDword(hKey, REG_KEY_SHUTDOWN_TIMEOUT, serviceParams.getShutdownMsecs())) { written = false; } // Set the overwite file flag (true for overwrite, false for append mode) if (written && !storeRegValueBoolean(hKey, REG_KEY_OVERWRITE_FILES_FLAG, serviceParams.getFileOverwriteFlag())) { written = false; } // Set the startup delay if (written && !storeRegValueDword(hKey, REG_KEY_STARTUP_DELAY, serviceParams.getStartupMsecs())) { written = false; } if (hKey != NULL) { RegCloseKey(hKey); } if (written) { written = setupAnonymousLogging() && setupServiceLogging(); } return written; }