Within my service i have the following function in order to take some values from my registry:
Public Function GetKeyValue(ByVal nKey As String, ByVal sPath As String) As String
Dim RegKey As RegistryKey
Dim kValue As String = Nothing
Dim Pos As String
If CheckRegistry(sPath) Then
Try
RegKey = Registry.CurrentUser.OpenSubKey(sPath)
kValue = CStr(RegKey.GetValue(nKey))
Catch ex As Exception
StartLogFile(" GetKeyValue " & vbNewLine & "Stack Trace= " & ex.StackTrace, EventLogEntryType.Warning)
End Try
End If
Return kValue
End Function
the same function works fine within a Windows form, but if i call from a service then she can't read the value. Is there anybody how knows what is going on?
There are two ways to open Registry Editor in Windows 10: In the search box on the taskbar, type regedit, then select Registry Editor (Desktop app) from the results. Right-click Start , then select Run. Type regedit in the Open: box, and then select OK.
The HKLM\SYSTEM\CurrentControlSet\Services registry tree stores information about each service on the system. Each driver has a key of the form HKLM\SYSTEM\CurrentControlSet\Services\DriverName. The PnP manager passes this path of a driver in the RegistryPath parameter when it calls the driver's DriverEntry routine.
Click Start, click Run, type regedit, and then click OK. Right-click winreg, and then click Permissions. Click Add.
There are three types of values; String, Binary, and DWORD - the use of these depends upon the context. There are six main branches, each containing a specific portion of the information stored in the Registry.
You should not store your data in HKEY_CURRENT_USER
but under HKEY_LOCAL_MACHINE
that makes more sense for a Windows-Service.
Be also aware that you can also set Permissions on Registry Keys. Check also that when try reading.
You are almost surely reading registry settings of a different user. The service likely runs as one of the built-in service user accounts: SYSTEM, LOCALSERVICE or NETWORKSERVICE. These are not interactive users.
Your design is fundamentally flawed and I suspect you will need to move these settings into a file which is not part of a user profile.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With