Sponsored Links

Login Form






Lost Password?

Syndicate

Home
Query Remote Registry Key PDF Print E-mail
User Rating: / 3
PoorBest 
Written by LazyNetworkAdmin   
I found this one in my archives. Once I had to find out a value of a registry key on all my domain PC's. This script will query either a single remote computer or an entire domain for the value of the specified key. 


----------COPY EVERYTHING BELOW THIS LINE----------

' Declare the constants
Const HKLM = &H80000002 ' HKEY_LOCAL_MACHINE
Const REG_SZ = 1 ' String value in registry (Not DWORD)
Const ForReading = 1
Const ForWriting = 2

' Set File objects...
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objDictionary = CreateObject("Scripting.Dictionary")
Set objDictionary2 = CreateObject("Scripting.Dictionary")

' Set string variables
strDomain = "DOMAINNAME" ' Your Domain
strPCsFile = "DomainPCs.txt"
strPath = "C:\scripts\" ' Create this folder
strWorkstationID = "C:\scripts\WorkstationID.txt"

If objFSO.FolderExists(strPath) Then
Wscript.Echo "This program will collect Workstation ID on remote compter(s)"
Else
Wscript.Echo "This program will collect Workstation ID on remote compter(s)"
WScript.Echo "Please create folder:  <c:\scripts> then click OK."
End If

' Get list of domain PCs - Using above variables.
strMbox = MsgBox("Would you like info for entire domain: DOMAINNAME ?",3,"Hostname")

'an answer of yes will return a value of 6, causing script to collect domain PC info
If strMbox = 6 Then
Set objPCTXTFile = objFSO.OpenTextFile(strPath & strPCsFile, ForWriting, True)
Set objDomain = GetObject("WinNT://" & strDomain) ' Note LDAP does not work
objDomain.Filter = Array("Computer")
For Each pcObject In objDomain
objPCTXTFile.WriteLine pcObject.Name
Next
objPCTXTFile.close

Else
'an answer of no will prompt user to input name of computer to scan and create PC file
strHost = InputBox("Enter the computer you wish to get Workstation ID","Hostname"," ")
Set strFile = objfso.CreateTextFile(strPath & strPCsFile, True)
strFile.WriteLine(strHost)
strFile.Close
End If


' Read list of computers from strPCsFile into objDictionary
Set readPCFile = objFSO.OpenTextFile(strPath & strPCsFile, ForReading)
i = 0
Do Until readPCFile.AtEndOfStream
strNextLine = readPCFile.Readline
objDictionary.Add i, strNextLine
i = i + 1
Loop
readPCFile.Close

' Run the procedure defined in the Sub routine GetWorkstationID()

For each DomainPC in objDictionary
strComputer = objDictionary.Item(DomainPC)
GetWorkstationID()
Next

Set objFilesystem = Nothing

WScript.echo "Finished Scanning Network check : " & strPath

Sub GetWorkstationID()

On Error Resume next

' WMI connection to the operating system note StdRegProv
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")

If Err <> "0" Then
Exit Sub
End If

' Registry paths which hold the WorkstationID information.
unKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\AppMgmt\{fae450a5-a221-4b05-9edb-de2f210db2ec}"
unValueName = ("Deployment Name")

' Enumerate Registry subkey paths for WorkstationID.
'objReg.EnumKey HKLM, unKeyPath
Set objTextFile1 = objFSO.OpenTextFile(strWorkstationID, ForWriting,True)
'For Each Subkey in arrSubKeys
objTextFile1.WriteLine (unKeyPath & (Enter))
'Next

' Read Registry info stored in the strWorkstationID file
Set objTextFile3 = objFSO.OpenTextFile(strWorkstationID, ForReading)

'pipe the WorkstationID paths from the WorkstationID.txt file into a second dictionary
i = 0
Do Until objTextFile3.AtEndOfStream
strNextLine = objTextFile3.Readline
objDictionary2.Add i, strNextLine
i = i + 1
Loop

' These paths are used in the filenames you see in the strPath
pcName = "SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName\"
pcNameValueName = "ComputerName"
userPath = "Software\Microsoft\Windows NT\CurrentVersion\Winlogon\"
userValueName = "DefaultUserName"
objReg.GetStringValue HKLM,pcName,pcNameValueName,pcValue
objReg.GetStringValue HKLM,userPath,userValueName,userValue

' Build up the filename found in the strPath
strFileName = UserValue & "_" & "On" & "_" & PCValue & "_" & "Workstation ID" _
& year(date()) & right("0" & month(date()),2) _
& right("0" & day(date()),2) & ".txt"

' Write each PC's software info file...
Set objTextFile2 = objFSO.OpenTextFile(strPath & strFileName, ForWriting, True)
' Writing info to the corresponding Software info file...
objTextFile2.WriteLine(vbCRLF & "==============================" & vbCRLF & _
"Current Workstation ID " & vbCRLF & Time & vbCRLF & Date _
& vbCRLF & "ID for:" & "" & userValue & vbCRLF & "On System:" _
& "" & pcValue & vbCRLF & "----------------------------------------" & vbCRLF)

' First enumeration also clean up if error exists (Second enumaration omitted)
For Each objItem in objDictionary2
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\AppMgmt\{fae450a5-a221-4b05-9edb-de2f210db2ec}"
objReg.GetstringValue HKLM ,strKeyPath, unValueName, strValue
objTextFile2.WriteLine (strValue)
If Err Then
objDictionary2.Remove(objItem)
End If
Next

End Sub

wscript.Quit

----------COPY EVERYTHING ABOVE THIS LINE----------

 

Change your

unKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\AppMgmt\{fae450a5-a221-4b05-9edb-de2f210db2ec}"

and


unValueName = ("Deployment Name")

to the key and value name you are searching for.

 You will also need to change your Domain Name to the Netbios Domain name you are looking to query.

 You must have a folder c:\scripts as the script will write to that directory.

 

This information is provided "AS IS" with no warranties expressed or implied.

 EDITED 5/2/2007: Unwanted word wrap occurred.

Comments
Add NewSearch
dmckelvey - A little Help Needed   | Registered | 01-05-2007 19:09:16
This looks like a awesome script and is exactly what I need. However, I can't seem to get it to work.

When I try and execute the script in it's original form I get some errors:

Line: 31
Char:1
Error: Expected statement
Code: 800A0400

Is there a If, Then statement missing?

If I remove the "End If" from Line 31 then I get the following error:

Line: 120
Char: 5
Error: Expected 'Sub'
Code: 800A03F8

Any help would be appreciated. Thanks!
chilifrei64 - Needs some work   | Super Administrator | 01-05-2007 19:27:02
Hrmm.. looks like my comments feature needs some work.. anyways..I can see your full question.
Here are a few things I would look at.
First, you must have the c:\scripts folder.
Second, you must change the domain name for the domain you want to scan.
Three, this has really only been tested on computers running windows scripting host 5.6.
Four, did you change the registry path and object name with what you are trying to scan.
I will test this script back out at work tomorrow when I have more time. In the mean time, please double check those.
dmckelvey - Needs some work   | Registered | 03-05-2007 09:04:13
Thanks for the response. Yes, I did create the "c:\scripts" folder as directed.

I also changed the domain name, registry path and object name. I will test it again to make sure.

How can you tell if the server is using WSH 5.6? Also, when I copy the info and paste it in I save it as a *.VBS file correct? Just wan to make sure.

Thanks!
chilifrei64 - Fixed   | Super Administrator | 03-05-2007 10:48:45
There was word wrapping happening in the page. I have updated the page. Copy it down again and make your changes and it should work now.
David Gaddy - Network Admin   | 72.250.228.xxx | 24-04-2008 10:00:27
what do I need to do to modify this script to scan for NETWARE printers on the network?

We are retiring our old Netware server and I need to remove and replace the old Netware print queues.

I want to look at the following key:
HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts

Thought If I find any machines left pointing to the old VWA server then I could narrow down my visits to every computer.

Thanks,

DG
Venkatesh VR - System Administrator     | 144.36.248.xxx | 28-05-2008 12:06:16
Can some one let me know how generate the report for specific DWORD & their value for the list of computers.
I have found one script which is not working properly. Means it will check for the first system in the file and provid the same result for all the systems. Basically it is not refreshing the vaule while looping. Please let me know if you have any suggetions

********************
*******************

Const HKEY_LOCAL_MACHINE = &H80000002

Const REG_SZ = 1
Const REG_EXPAND_SZ = 2
Const REG_BINARY = 3
Const REG_DWORD = 4
Const REG_MULTI_SZ = 7

HostFile = "d:\ServerLists.txt"

On error Resume Next

set objDictionary = CreateObject("Scripting.Dictionary"
Set objFSO1 = CreateObject("Scripting.FileSystemObject"
Set objTextFile = objFSO1.OpenTextFile _
(HostFile, 1)
x = 1
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.ReadLine
objDictionary.Add x, strNextLine
x = x + 1
Loop

For Each objItem in objDictionary
...
Renato   | 64.205.249.xxx | 19-06-2008 12:36:00
I had to comment out the section where it asks you to do the entire domain so that it will go down to read the PCs.txt file.
Write comment
Name:
Email:
 
Website:
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
 
 
Security Image
Please input the anti-spam code that you can read in the image.

Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved.

 
Tag it:
Delicious
Furl it!
Spurl
digg
YahooMyWeb
< Prev   Next >
 

Google Search

Google