Added set_expand_string() and set_number().

Helper functions to set REG_EXPAND_SZ and REG_DWORD values in the
registry.
master
Iain Patterson 11 years ago
parent bf75c3da8b
commit 0f64692bef

@ -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.

@ -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);

Loading…
Cancel
Save