-4

The task is to first scan the local machine for a Valid Computer name (which I've done) then with that Computer name it should check a CSV to pipe the Username and Password sections somewhere.

My CSV reads as follows:

COMPUTERNAME1,USERNAME1,PASSWORD1
COMPUTERNAME2,USERNAME2,PASSWORD2
COMPUTERNAME3,USERNAME3,PASSWORD3

So if, for example, the VBS detects the computer name using the VBS:

Set wshShell = CreateObject( "WScript.Shell" )
strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )

..And it detects the computer name is called: COMPUTERNAME2

Then the VBS should then look up that declared "strComputerName" in the CSV (which is "COMPUTERNAME2") and pipe the associated next two lines for USERNAME2,PASSWORD2 which I can then pipe again to an autologin script (which I have) so Autologin will associate that Computer Name to the Username and Password.

The objective is we're running an active CSV so the list of machines will grow so the key is just detect for the appropriate computer name.

JNevill
  • 46,980
  • 4
  • 38
  • 63
Thudo
  • 1

1 Answers1

1

You can use FSO to read a file:

Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\FSO\ScriptLog.txt", ForReading)
 Do While objFile.AtEndOfStream = False
    strLine = objFile.ReadLine
    If computername = Split(strLine, ",")(0) Then
        'found a matching computer name
        username = Split(strLine, ",")(1)
        plaintextpasswordomg = Split(strLine, ",")(2)
    End If
 Loop
 objFile.Close
 Set objFile = Nothing
 Set objFSO = Nothing

It loops each line of the file and then test for the computername and capture the username/pass into variables using Split() to split the line into an array using a comma as the delimiter.

JNevill
  • 46,980
  • 4
  • 38
  • 63