Page 1 of 1

Query list of workstations for registry string value

Posted: Thu Nov 21, 2013 2:32 pm
by rcjay272
All,

I am trying to create a script to read a txt file with workstation names and then read a value in HKLM. I have it partially working but I can't get it to read the registry information. I have a standalone VBS to query and echo out the values but I am having an issue with the whole process of reading the text file then querying the workstation.

I am looking for help in trying to get the reg query correct.
VBScript Code
Double-click the code block to select all.
On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
const HKEY_LOCAL_MACHINE = &H80000002

Set StdOut = WScript.StdOut
Dim strComputer
Dim strKeyPath
Dim strValueName

set strValueName="Shell"
set strKeyPath="SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objUserFile = objFSO.OpenTextFile("C:\rcj\scripts\regquery\ws.txt", 1)

Do While objUserFile.AtEndOfStream <> True
	strComputer = objUserFile.ReadLine
	strComputer = Trim(strComputer)
	
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")

'oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue


Set colFiles = oReg.GetStringValue (HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue)

   For Each objFile in colFiles

		
		WScript.Echo "Current Shell Value: " & vbTab & strComputer & vbTab & strValue
		wscript.echo & vbTab & strComputer
		wscript.echo & vbTab & strValue
Next

Loop

objUserFile.Close

Function WMIDateStringToDate(dtmDate)
WScript.Echo dtm: 
	WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _
	Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) _
	& " " & Mid (dtmDate, 9, 2) & ":" & Mid(dtmDate, 11, 2) & ":" & Mid(dtmDate,13, 2))
End Function

Re: Query list of workstations for registry string value

Posted: Thu Nov 21, 2013 3:11 pm
by jvierra
Start by removing this line:
On Error Resume Next

Re: Query list of workstations for registry string value

Posted: Thu Nov 21, 2013 3:23 pm
by jvierra
Here is a less mussy version.
VBScript Code
Double-click the code block to select all.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objUserFile = objFSO.OpenTextFile("C:\rcj\scripts\regquery\ws.txt")

Do While Not objUserFile.AtEndOfStream

    strComputer = Trim(objUserFile.ReadLine)
    Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
    On Error Resume Next
    Set colFiles = oReg.GetStringValue(&H80000002,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon","Shell", strValue)
    If Err <> 0 Then
         WScript.Echo Err.Description
    Else
        For Each objFile in colFiles
            WScript.Echo "Shell for Computer:" & strComputer & "Value: " & strValue
        Next
    End If
    On Error GoTo 0
Loop
objUserFile.Close
Do not try to be fancy with code until you understand what it is doing. Fancy is for building public apps. Sparse is for learning.

There is no such key as the one you are looking for. The error message will show that.

Re: Query list of workstations for registry string value

Posted: Thu Nov 21, 2013 3:30 pm
by rcjay272
Been there done that. I am lost at this point.

Re: Query list of workstations for registry string value

Posted: Thu Nov 21, 2013 3:41 pm
by jvierra
What is it that you are trying to do. There is no such value at that key. Why do you think there is?

Re: Query list of workstations for registry string value

Posted: Thu Nov 21, 2013 4:13 pm
by rcjay272
Sure there is....

c:\RCJ\Scripts\regquery>reg query "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v Shell

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon
Shell REG_SZ explorer.exe

Ultimately I want to read a txt file of workstation names and query a registry location on each and then output to the screen.

Re: Query list of workstations for registry string value

Posted: Thu Nov 21, 2013 5:17 pm
by jvierra
I have no machines with that value.

It is also not clear what you need to do or what the problem is.

Re: Query list of workstations for registry string value

Posted: Thu Nov 21, 2013 5:18 pm
by jvierra
I gave you the solution. If the value shows as missing then it is missing. If you are looking at a the r32 bit version of REG then you need to say so.

Re: Query list of workstations for registry string value

Posted: Thu Nov 21, 2013 7:51 pm
by jvierra
I thought I should clarify. If you are on a 64 bit machine and you are running a 32 bit tool you may see different results.

Exactly what is it that you are trying to do?