Lef*_*nis 5 .net vb.net registry windows-services
在我的服务中,我具有以下功能,以便从我的注册表中获取一些值:
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
Run Code Online (Sandbox Code Playgroud)
相同的功能在 Windows 窗体中工作正常,但如果我从服务调用,则她无法读取该值。有没有人知道发生了什么?
您不应该将数据存储在其中,HKEY_CURRENT_USER但HKEY_LOCAL_MACHINE对于 Windows 服务来说更有意义。
另请注意,您还可以设置注册表项的权限。尝试阅读时还要检查一下。