How to use Getsetting/Savesetting in Windows Services

Asked

Viewed 226 times

2

I created a service and configured it as Localsystem.

In the implementation I try to search for a record saved on REGEDIT by another programme. The method GetSetting always returns me empty. Is there any way to recover/save data on REGEDIT using Windows Services?

3 answers

2

2


You’re giving in to reading permission as the function requires? If you prefer another way to obtain and change this data, you can use the class methods RegistryKey for that reason.

To recover a value you can use the method GetValue().

const string REG_KEY_NAME = @"SOFTWARE\Bar\Baz";
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(REG_KEY_NAME, false)) // Abrir a key para leitura
{
    string Valor = key.GetValue("NomeDoValor").ToString();
}

To change a value or data, you can use the method SetValue().

using (RegistryKey key = Registry.CurrentUser.OpenSubKey(REG_KEY_NAME, true)) // Abrir a key para leitura/gravação
{
    key.SetValue("NomeDoValor", "FooBar");
}

I put in the Github for future reference.

0

I solved my problem using a file XML to store the data I will use later.

Certainly not the best way, but as mine serviço is as LocalSystem and has Service User permissions so I can’t have access to CurrentUser, so I can’t get the values.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.