Query list of workstations for registry string value

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
rcjay272
Posts: 3
Joined: Sun Mar 03, 2013 12:38 pm

Query list of workstations for registry string value

Post by rcjay272 » Thu Nov 21, 2013 2:32 pm

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

jvierra
Posts: 14019
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Query list of workstations for registry string value

Post by jvierra » Thu Nov 21, 2013 3:11 pm

Start by removing this line:
On Error Resume Next

jvierra
Posts: 14019
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Query list of workstations for registry string value

Post by jvierra » Thu Nov 21, 2013 3:23 pm

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.

User avatar
rcjay272
Posts: 3
Joined: Sun Mar 03, 2013 12:38 pm

Re: Query list of workstations for registry string value

Post by rcjay272 » Thu Nov 21, 2013 3:30 pm

Been there done that. I am lost at this point.

jvierra
Posts: 14019
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Query list of workstations for registry string value

Post by jvierra » Thu Nov 21, 2013 3:41 pm

What is it that you are trying to do. There is no such value at that key. Why do you think there is?

User avatar
rcjay272
Posts: 3
Joined: Sun Mar 03, 2013 12:38 pm

Re: Query list of workstations for registry string value

Post by rcjay272 » Thu Nov 21, 2013 4:13 pm

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.

jvierra
Posts: 14019
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Query list of workstations for registry string value

Post by jvierra » Thu Nov 21, 2013 5:17 pm

I have no machines with that value.

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

jvierra
Posts: 14019
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Query list of workstations for registry string value

Post by jvierra » Thu Nov 21, 2013 5:18 pm

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.

jvierra
Posts: 14019
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Query list of workstations for registry string value

Post by jvierra » Thu Nov 21, 2013 7:51 pm

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?

Locked