___ erkimt ___ How to use GetSetting / SaveSetting in Windows Services ______ qstntxt ___
I created a service and configured it as LocalSystem .
In the implementation I try to fetch a record saved in RegistryKey
by another program. The method
GetValue()
always returns me empty. Is there any way to recover / save data in SetValue()
using Windows Services?
You are giving the read permission as the function requires? If you prefer another way to get and change this data, you can use the methods of the %code% for it.
To retrieve a value you can use the method %code% .
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 %code% .
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(REG_KEY_NAME, true)) // Abrir a key para leitura/gravação
{
key.SetValue("NomeDoValor", "FooBar");
}
What you want is usually obtained through the %code% class. . Something like this:
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();
}
I solved my problem using a %code% file to store the data I will use later.
It's certainly not the best way, but since my %code% is as %code% and has Service User permissions so I can not access the %code% records, so I can not get the values