How to use GetSetting / SaveSetting in Windows Services

2

I created a service and configured it as LocalSystem .

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

    
asked by anonymous 17.01.2015 / 13:15

3 answers

2
___ 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?

    
______ ___ azszpr47291

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");
}
    
______ azszpr47288 ___

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();
}
    
______ azszpr47485 ___

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

    
___
17.01.2015 / 14:15
2

What you want is usually obtained through the Registry class. . Something like this:

Registry.GetValue("HKEY_CURRENT_USER\Chave", "ChaveEspecifica", 0)
    
17.01.2015 / 13:25
0

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

It's certainly not the best way, but since my serviço is as LocalSystem and has Service User permissions so I can not access the CurrentUser records, so I can not get the values

    
19.01.2015 / 18:49