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.
This topic is 10 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
rcjay272
Posts: 3
Last visit: Thu Jul 30, 2015 9:48 am

Query list of workstations for registry string value

Post 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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Query list of workstations for registry string value

Post by jvierra »

Start by removing this line:
On Error Resume Next
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Query list of workstations for registry string value

Post 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.
User avatar
rcjay272
Posts: 3
Last visit: Thu Jul 30, 2015 9:48 am

Re: Query list of workstations for registry string value

Post by rcjay272 »

Been there done that. I am lost at this point.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Query list of workstations for registry string value

Post 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?
User avatar
rcjay272
Posts: 3
Last visit: Thu Jul 30, 2015 9:48 am

Re: Query list of workstations for registry string value

Post 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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Query list of workstations for registry string value

Post by jvierra »

I have no machines with that value.

It is also not clear what you need to do or what the problem is.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Query list of workstations for registry string value

Post 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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Query list of workstations for registry string value

Post 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?
This topic is 10 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked