Link to home
Start Free TrialLog in
Avatar of fruitloopy
fruitloopy

asked on

VB.NET - Loop through text file and modify registry on each PC in list

I cannot see why I cant get this to work!
I will have a text file generated from another function with a computer name and password like this:
C001356395,examplepassword

I want to loop through each line, separate the computer name from the password and update the DefaultPassword field in the registry of each remote computer.
My main problem is that it is not connecting to the remote registry of each PC.
Code:
Dim text As String = txtFile.Text
        If text <> "" Then
            Try
                Dim str2 As String = File.OpenText(text).ReadLine
                Dim reader2 As New StreamReader(text)
                Do While Not reader2.EndOfStream
                    str2 = reader2.ReadLine
                    Dim num As Integer = Strings.InStr(str2, ",", CompareMethod.Binary)
                    Dim str3 As String = Strings.Left(str2, (num - 1))
                    Dim str4 As String = Strings.Right(str2, (Strings.Len(str2) - num))
                    MsgBox(str3)
                    Dim regkey As Microsoft.Win32.RegistryKey = RegistryKey.OpenRemoteBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, str3)
                    regkey.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", True)

                    regkey.SetValue("DefaultPassword", str4, Microsoft.Win32.RegistryValueKind.String)
                Loop
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try

        End If

Open in new window

I think the problem is this part: RegistryKey.OpenRemoteBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, str3) where str3 is the computer name. The msgbox(str3) correctly shows the computer name.
I have also changed the code to just read a value from the remote computer but it just doesnt seem to connect.
ASKER CERTIFIED SOLUTION
Avatar of fruitloopy
fruitloopy

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial