0

我正在尝试编写一个程序来检查注册表中 Windows 服务的起始值,并且我正在使用 Dictionary(of String, Point) 将服务的名称存储在注册表中 (String) 以及 Default 和 True 起始值起始值(点)X 为默认值,Y 为真。

Private _defaultRegistryVals As New Dictionary(Of String, Point)

Public Enum StartupMode
        Disabled = 0
        Manual = 1
        Auto = 2
        AutoDelayed = 3
    End Enum

Private Function Analyze as Boolean
Dim mostOfRegistryPath As String = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\"
 If Not _HasLoaded then

_defaultRegistryVals.Add("AxInstSV", New Point(StartupMode.Manual, 0)) 
_defaultRegistryVals.Add("SensrSvc", New Point(StartupMode.Manual, 0))
_defaultRegistryVals.Add("AeLookupSvc", New Point(StartupMode.Manual, 0))

_HasLoaded = True

End If

For Each kvp As KeyValuePair(Of String, Point) In _defaultRegistryVals

Try 

kvp.Value.Y = TryCast( My.Computer.Registry.GetValue (mostOfRegistryPath + kvp.Key),      "Start", Nothing), double)
Catch ex As Exception

End Try

Next kvp 

由于字典是只读的,因此我的程序从注册表中获取每个 Windows 服务的起始值的真实值的最佳方法是什么。我应该让它检查每个值作为添加字典条目吗?或者,还有更好的方法?

这不是完整的代码,而是它工作所需的代码片段。大多数其他代码只是整个服务列表,以及检查Windows版本的按钮,然后开始分析注册表。

4

1 回答 1

1

试试下面的代码

    Dim DictionaryKeys1(_defaultRegistryVals.Count - 1) As String

    _defaultRegistryVals.Keys.CopyTo(DictionaryKeys1, 0)

    For Each KeyValue In DictionaryKeys1
        Try
            Dim RegistryValue1 As String = CStr(My.Computer.Registry.GetValue(mostOfRegistryPath + KeyValue, "Start", Nothing))

            If Not RegistryValue1 Is Nothing Then
                Dim Point1 As New Point

                Point1.X = _defaultRegistryVals(KeyValue).X
                Point1.Y = CInt(RegistryValue1)

                _defaultRegistryVals(KeyValue) = Point1
            End If
        Catch ex As Exception
            MsgBox("Error")
        End Try
    Next
于 2013-07-13T21:41:20.163 回答