Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2014-07-16
1
Medium Priority
?
222 Views
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:
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.
0
Comment
Question by:fruitloopy
1 Comment
 
LVL 2

Accepted Solution

by:
fruitloopy earned 0 total points
ID: 40198999
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
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses

569 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