From: Iain Patterson Date: Wed, 20 Nov 2013 15:20:02 +0000 (+0000) Subject: Added set_expand_string() and set_number(). X-Git-Tag: v2.19~10 X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=0f64692bef62a3be6f9352cfdee05d73130d06f4;p=nssm.git Added set_expand_string() and set_number(). Helper functions to set REG_EXPAND_SZ and REG_DWORD values in the registry. --- diff --git a/registry.cpp b/registry.cpp index 7eb6112..f54ed03 100644 --- a/registry.cpp +++ b/registry.cpp @@ -191,6 +191,28 @@ int expand_parameter(HKEY key, char *value, char *data, unsigned long datalen, b return expand_parameter(key, value, data, datalen, sanitise, true); } +/* + Sets a string in the registry. + Returns: 0 if it was set. + 1 on error. +*/ +int set_expand_string(HKEY key, char *value, char *string) { + if (RegSetValueEx(key, value, 0, REG_EXPAND_SZ, (const unsigned char *) string, (unsigned long) strlen(string) + 1) == ERROR_SUCCESS) return 0; + log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_SETVALUE_FAILED, value, error_string(GetLastError()), 0); + return 1; +} + +/* + Set an unsigned long in the registry. + Returns: 0 if it was set. + 1 on error. +*/ +int set_number(HKEY key, char *value, unsigned long number) { + if (RegSetValueEx(key, value, 0, REG_DWORD, (const unsigned char *) &number, sizeof(number)) == ERROR_SUCCESS) return 0; + log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_SETVALUE_FAILED, value, error_string(GetLastError()), 0); + return 1; +} + /* Query an unsigned long from the registry. Returns: 1 if a number was retrieved. diff --git a/registry.h b/registry.h index 17f26d7..5d42792 100644 --- a/registry.h +++ b/registry.h @@ -26,6 +26,8 @@ int create_exit_action(char *, const char *); int set_environment(char *, HKEY, char **); int expand_parameter(HKEY, char *, char *, unsigned long, bool, bool); int expand_parameter(HKEY, char *, char *, unsigned long, bool); +int set_expand_string(HKEY, char *, char *); +int set_number(HKEY, char *, unsigned long); int get_number(HKEY, char *, unsigned long *, bool); int get_number(HKEY, char *, unsigned long *); void override_milliseconds(char *, HKEY, char *, unsigned long *, unsigned long, unsigned long);