Test registry value on remote machine

General chat about HostMonitor
Post Reply
kkern
Posts: 4
Joined: Mon Jun 16, 2003 6:00 pm

Test registry value on remote machine

Post by kkern »

I am trying to evaluate a registry key entry from a remote Windows server and I'm having a hard time putting all the pieces together. Could someone point me in the right direction to figuring this out (if there is a way).

I would like to test a Windows Update registry key to see if the server needs a reboot after an automatic update. I started with the readreg.vbs example (by the way, I'm not too familiar with VBscript programming, so it is a little bit of a challenge). But I don't see how a computer name ties into it. Would I have to set up RMA on each server to run the VBscript correctly?

Or is there a test I missed reading about that I can point into at Windows Registry keys that will give to the same thing? Any other suggestions/recommendations to accomplish the same testing would be helpful too if this proves resource-consuming.

Thanks.
KS-Soft
Posts: 12821
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Truth to say I am not expert in VB either. But I think you can find some useful scripts on http://search.winnetmag.com/#code

There is examle of the script that reads registry of the local system using WMI
http://www.microsoft.com/technet/commun ... reg16.mspx

Code: Select all

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set StdOut = WScript.StdOut
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_ 
strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion"
strValueName = "LicenseInfo"
oReg.GetBinaryValue HKEY_LOCAL_MACHINE,strKeyPath,_
strValueName,strValue
For i = lBound(strValue) to uBound(strValue)
    StdOut.WriteLine  strValue(i)
Next
I assume you can change strComputer = "." line to something like strComputer = "\\server"

Regards
Alex
kkern
Posts: 4
Joined: Mon Jun 16, 2003 6:00 pm

Post by kkern »

I'll have to try that this morning and see how it works. I did find something late last night that might work. Turns out Windows XP (Pro only?) has a program called reg.exe that allows you to query/compare/add/delete/etc registry information.

Looks like "reg compare KEY KEY /v Value" will return an errorlevel code that I can evaluate with the External Program test in HM. The only odd catch is I created a custom registry key on the HM server with the value I want to test against (0x8). Not sure how well this will work for other tests I can think up later.

Thanks for your help ...
User avatar
plambrecht
Posts: 151
Joined: Wed May 19, 2004 8:11 am
Location: Belgium
Contact:

Post by plambrecht »

Hi,

Try this code :

Code: Select all


Dim objReg
Set objReg = wscript.CreateObject("RegObj.Registry")
if err <> 0 then
	WScript.StdOut.Write "scriptres:" & StatusBad & "REGOBJ.DLL not found. Please install & register regobj.dll"
	WScript.Quit
End if 

Function ReadRemoteReg(rserver, root, value1, byref retregval)
on error resume next
Dim objRemote, objRegKey, regVal
	'connect to remote server
	Set objRemote = objReg.RemoteRegistry(rserver)
	if err <> 0 then
		ReadRemoteReg = err.number
		retregval = err.description & " - Unable to connect to server " & ucase(rserver)
		Set ObjRemote = Nothing
		exit Function
	End if 
	
	'open regkey
	Set objRegkey = objRemote.RegKeyFromString(root)
	if err <> 0 then
		ReadRemoteReg = err.number
		retregval = err.description & " - Regkey " & root & " not found on server " & ucase(rserver)
		Set ObjRemote = Nothing
		Set objRegKey = Nothing
		exit Function
	End if 
	
	'and read values
	regval = objRegKey.Values(value1).Value
	if err <> 0 then
		ReadRemoteReg = err.number
		retregval = err.description & " - Unable to read RegValue '" & value1 & "'"
		exit Function
	Else
		ReadRemoteReg = 0
		retregval = RegVal
	End If

	Set ObjRemote = Nothing
	Set objRegKey = Nothing
End Function

If ReadRemoteReg("SERVER-FS1", "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentVersion", RetVal)=0 Then
	WScript.StdOut.Write "scriptres:OK:" & RetVal
Else
	WScript.StdOut.Write "scriptres:Bad:" & RetVal
End if

It requieres RegObj.dll.. (http://download.microsoft.com/download/ ... egobji.exe)

Pieter
terje
Posts: 88
Joined: Mon Jul 25, 2005 7:45 pm
Location: Sydney

Post by terje »

I presume I just create a VB script within hostmonitors scriptmanager and use the script content from above verbatim. But what are the parameters I should pass?

Perhaps somebody that is good at reading VB script can help.
KS-Soft
Posts: 12821
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

That script uses hard-coded parameters

Code: Select all

...
If ReadRemoteReg("SERVER-S1", "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentVersion", RetVal)=0 Then 
...
Parameters are: server_name, key_name, variable_name

Regards
Alex
Post Reply