在我的服务中,我具有以下功能,以便从我的注册表中获取一些值:
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
相同的功能在 Windows 窗体中工作正常,但如果我从服务调用,则她无法读取该值。
有没有人知道发生了什么?
最佳答案
您不应将数据存储在 HKEY_CURRENT_USER
中但在 HKEY_LOCAL_MACHINE
下这对 Windows 服务更有意义。
另请注意,您还可以设置注册表项的权限。尝试阅读时还要检查一下。
关于.net - 我无法从服务读取注册表值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5370206/