cannot acces to registre using getvalue

Posted by Tobi under C# on 6/5/2013 | Points: 10 | Views : 1235 | Status : [Member] | Replies : 1
hi everybody
i have a small problem
i want to access to registre with a localsystem service to check a key value (to check if the usb is activated or not)

i dont know if there is a probleme with permissions(session,currentuser) but i want my service to be independent from the user session

i tried this but it doesn t work:

RegistryKey mycle = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Service\USBSTORE", false);
var cle = Registry.GetValue(@"SYSTEM\CurrentControlSet\Service\USBSTORE", "start", -1);

first i know that the value is 3 or 4 to check if the usb is activated but i dont know how to cast the return type of getvalue
i also dont know if the method opensubkey is better than this
int cle = (int)Registry.GetValue(@"SYSTEM\CurrentControlSet\Service\USBSTORE", "start", -1);

i found something like this (should i use it??) : if (Environment.Is64BitOperatingSystem)
localKey = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry64);
localKey = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry32);
please help me...


Posted by: Tobi on: 6/6/2013 [Member] Starter | Points: 25

this code is right
i juste had to change the path
thanks everybody

Tobi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response