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

Posted on 2014-07-16
Last Modified: 2014-07-16
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:

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.
Dim text As String = txtFile.Text
        If text <> "" Then
                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))
                    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)
            Catch ex As Exception
            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.
Question by:fruitloopy
    1 Comment
    LVL 2

    Accepted Solution

    Just for future reference and hopefully it may help someone else who is close to slitting their wrists..

    In Visual Studio 2012 it has this annoying habit of defaulting to the Wow6432bit node of a 64bit system. You have to remove a tick from the "Prefer 32-bit" box located in:
    Project - Properties - Compile
    Also make sure the Target CPU is set to AnyCPU

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Suggested Solutions

    Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
    In my previous article ( we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    This video discusses moving either the default database or any database to a new volume.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now