سؤال

I am trying to code a program that checks the start values for windows services in the registry and I am using a Dictionary(of String, Point) to store the name of the service in the registry(String) and the Default and True start values of the Start value(Point) X being Default, and Y being True.

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 

Since the Dictionary is Read only, what would be the best way for my program to get the true values of the Start Value for each Windows service from the registry. Should I have it check each Value as its adding the Dictionary entries? or is there a better way?

This isn't the whole code, but its the snippits that are needed for it to work somewhat. Most of the other code is just the whole list of services, and the button to check windows version, then start analyzing the registry.

هل كانت مفيدة؟

المحلول

Try the following code

    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
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top