KS-Soft. Network Management Solutions
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister    ProfileProfile    Log inLog in 

Test registry value on remote machine

 
Post new topic   Reply to topic    KS-Soft Forum Index -> Other
View previous topic :: View next topic  
Author Message
kkern



Joined: 16 Jun 2003
Posts: 4

PostPosted: Wed Jul 28, 2004 1:25 pm    Post subject: Test registry value on remote machine Reply with quote

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.
Back to top
View user's profile Send private message
KS-Soft



Joined: 03 Apr 2002
Posts: 12795
Location: USA

PostPosted: Wed Jul 28, 2004 8:34 pm    Post subject: Reply with quote

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/community/scriptcenter/registry/scrreg16.mspx
Code:
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
Back to top
View user's profile Send private message Visit poster's website
kkern



Joined: 16 Jun 2003
Posts: 4

PostPosted: Thu Jul 29, 2004 5:48 am    Post subject: Reply with quote

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 ...
Back to top
View user's profile Send private message
plambrecht



Joined: 19 May 2004
Posts: 151
Location: Belgium

PostPosted: Wed Oct 13, 2004 8:28 am    Post subject: Reply with quote

Hi,

Try this code :
Code:


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/vb60pro/update/6.0/w9x2k/en-us/regobji.exe)

Pieter
Back to top
View user's profile Send private message Visit poster's website
terje



Joined: 25 Jul 2005
Posts: 88
Location: Sydney

PostPosted: Tue Sep 27, 2005 6:27 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
KS-Soft



Joined: 03 Apr 2002
Posts: 12795
Location: USA

PostPosted: Tue Sep 27, 2005 11:43 am    Post subject: Reply with quote

That script uses hard-coded parameters
Code:
...
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
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    KS-Soft Forum Index -> Other All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group

KS-Soft Forum Index