int ACE_Log_Msg_NT_Event_Log::open (const ACE_TCHAR *logger_key) { // ACE's "resource module" contains the message resource required // for event logging. ACE_TCHAR msg_file [MAXPATHLEN]; if (!ACE_TEXT_GetModuleFileName (ACE_OS::get_win32_resource_module (), msg_file, MAXPATHLEN)) return -1; DWORD msg_file_length = static_cast<DWORD> ((ACE_OS::strlen (msg_file) + 1) * sizeof (ACE_TCHAR)); // If a logger_key has been supplied then we use that as the event // source name, otherwise we default to the program name. const ACE_TCHAR *event_source_name = logger_key ? logger_key : ACE_Log_Msg::program_name (); // Information is stored in the registry at a location based on the // program name. ACE_TCHAR reg_key [MAXPATHLEN]; ACE_OS::strcpy (reg_key, ACE_TEXT ("SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\")); size_t reg_key_length = ACE_OS::strlen(reg_key); ACE_OS::strncat (reg_key, event_source_name, MAXPATHLEN - reg_key_length); // Add the event source to the registry. Note that if this fails it // is not fatal. The application will still be able to write entries // to the event log, they just won't be formatted correctly. HKEY hkey; ACE_TEXT_RegCreateKey (HKEY_LOCAL_MACHINE, reg_key, &hkey); DWORD flags = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE; ACE_TEXT_RegSetValueEx (hkey, ACE_TEXT ("TypesSupported"), 0, REG_DWORD, (LPBYTE) &flags, sizeof (DWORD)); ACE_TEXT_RegSetValueEx (hkey, ACE_TEXT ("EventMessageFile"), 0, REG_SZ, (LPBYTE) msg_file, msg_file_length); RegCloseKey (hkey); // Obtain a handle to the event source. this->evlog_handle_ = ACE_TEXT_RegisterEventSource (0, event_source_name); return this->evlog_handle_ ? 0 : -1; }
int Activator_Options::save_registry_options() { #if defined (ACE_WIN32) HKEY key = 0; // Create or open the parameters key LONG err = ACE_TEXT_RegCreateKeyEx (SERVICE_REG_ROOT, SERVICE_REG_PATH, 0, const_cast<ACE_TCHAR *> (ACE_TEXT("")), // class REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0, &key, 0 ); if (err != ERROR_SUCCESS) { return -1; } err = ACE_TEXT_RegSetValueEx (key, ACE_TEXT("ORBInitOptions"), 0, REG_SZ, (LPBYTE) this->cmdline_.c_str (), (DWORD) this->cmdline_.length () + 1); ACE_ASSERT (err == ERROR_SUCCESS); err = ACE_TEXT_RegSetValueEx (key, ACE_TEXT("IORFile"), 0, REG_SZ, (LPBYTE) this->ior_output_file_.c_str (), (DWORD) this->ior_output_file_.length () + 1); ACE_ASSERT (err == ERROR_SUCCESS); err = ACE_TEXT_RegSetValueEx (key, ACE_TEXT("DebugLevel"), 0, REG_DWORD, (LPBYTE) &this->debug_ , sizeof (this->debug_)); ACE_ASSERT (err == ERROR_SUCCESS); err = ACE_TEXT_RegSetValueEx( key, ACE_TEXT("Name"), 0, REG_SZ, (LPBYTE) this->name_.c_str (), (DWORD) this->name_.length () + 1); ACE_ASSERT (err == ERROR_SUCCESS); DWORD tmpint = this->notify_imr_; err = ACE_TEXT_RegSetValueEx (key, ACE_TEXT("NotifyImR"), 0, REG_DWORD, (LPBYTE) &tmpint , sizeof (tmpint)); ACE_ASSERT (err == ERROR_SUCCESS); tmpint = this->env_buf_len_; err = ACE_TEXT_RegSetValueEx(key, ACE_TEXT("EnvBufLen"), 0, REG_DWORD, (LPBYTE) &tmpint , sizeof(tmpint)); ACE_ASSERT(err == ERROR_SUCCESS); tmpint = this->max_env_vars_; err = ACE_TEXT_RegSetValueEx(key, ACE_TEXT("MaxEnvVars"), 0, REG_DWORD, (LPBYTE) &tmpint , sizeof(tmpint)); ACE_ASSERT(err == ERROR_SUCCESS); err = ::RegCloseKey (key); ACE_ASSERT (err == ERROR_SUCCESS); #endif return 0; }
// Insert or update <object> with <name> into <this> context // (String version) int ACE_Registry::Naming_Context::bind (const ACE_TString &name, const Object &object) { long result = ACE_TEXT_RegSetValueEx (this->key_, name.c_str (), 0, object.type (), (const BYTE *) object.data (), object.size ()); ACE_REGISTRY_CALL_RETURN (result); }
void TAO_NT_Notify_Service::arg_manip (char *args, DWORD arglen, bool query) { HKEY hkey = 0; // It looks in the NT Registry under // \\HKEY_LOCAL_MACHINE\SOFTWARE\ACE\TAO for the value of // "TaoNotifyServiceOptions" for any Notify Service options such as // "-ORBListenEndpoints". // Get/Set Notify Service options from the NT Registry. LONG result = ACE_TEXT_RegOpenKeyEx (REGISTRY_KEY_ROOT, TAO_REGISTRY_SUBKEY, 0, query ? KEY_READ : KEY_WRITE, &hkey); DWORD type = REG_EXPAND_SZ; if (query) { *args = '\0'; if (result == ERROR_SUCCESS) { result = ACE_TEXT_RegQueryValueEx (hkey, TAO_NOTIFY_SERVICE_OPTS_NAME, 0, &type, (BYTE *)args, &arglen); if (result != ERROR_SUCCESS) { this->report_error (ACE_TEXT ("Could not query %s, %s\n"), TAO_NOTIFY_SERVICE_OPTS_NAME, result); } } else { this->report_error (ACE_TEXT ("No key for %s, %s\n"), TAO_REGISTRY_SUBKEY, result); } } else { if (result != ERROR_SUCCESS) { result = ACE_TEXT_RegCreateKeyEx (REGISTRY_KEY_ROOT, TAO_REGISTRY_SUBKEY, 0, 0, 0, KEY_WRITE, 0, &hkey, 0); } DWORD bufSize = static_cast<DWORD>(ACE_OS::strlen (args) + 1); if (result == ERROR_SUCCESS) { result = ACE_TEXT_RegSetValueEx (hkey, TAO_NOTIFY_SERVICE_OPTS_NAME, 0, type, (BYTE *)args, bufSize); if (result != ERROR_SUCCESS) { this->report_error (ACE_TEXT ("Could not set %s, %s\n"), TAO_NOTIFY_SERVICE_OPTS_NAME, result); } } else { this->report_error (ACE_TEXT ("Could not create key %s, %s\n"), TAO_REGISTRY_SUBKEY, result); } } RegCloseKey (hkey); }