1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Problem Script required to read remote registry key

Discussion in 'Scripting & Programming' started by Boycie, Apr 25, 2010.

  1. Boycie
    Honorary Member

    Boycie Senior Beer Tester

    6,281
    85
    174
    hi,

    I am just starting to look around for a script which will read a registry key on (remote) xp machines. Ideally, this script will write to .csv on a shared folder on the server (2k3 standard).
    Software has been deployed via gpo some time ago and I need to ensure the machines in this policy are now using the correct version of software.

    thanks!
     
    Certifications: MCSA 2003, MCDST, A+, N+, CTT+, MCT
  2. SimonD

    SimonD Terabyte Poster Moderator

    3,463
    397
    199
    Is this any help? It's WMI based but should report back what you need.

    Luckily enough I don't need to do a lot of scripting, I let Config Manager do it's thing instead.
     
    Certifications: CNA | CNE | CCNA | MCP | MCP+I | MCSE NT4 | MCSA 2003 | Security+ | MCSA:S 2003 | MCSE:S 2003 | MCTS:SCCM 2007 | MCTS:Win 7 | MCITP:EDA7 | MCITP:SA | MCITP:EA | MCTS:Hyper-V | VCP 4 | ITIL v3 Foundation | VCP 5 DCV | VCP 5 Cloud | VCP6 NV | VCP6 DCV | VCAP 5.5 DCA
    WIP: VCP6-CMA, VCAP-DCD and Linux + (and possibly VCIX-NV).
  3. zebulebu

    zebulebu Terabyte Poster

    3,748
    330
    187
    Boycey

    Here's what I use (currently used for pulling the agent GUID version from a list of remote boxes fed in via a text file - easily adapted to fit almost any circumstance)

    Code:
    Option Explicit
    Const HKEY_LOCAL_MACHINE = &H80000002
    Dim Computer, Registry, Result, AgentGUID
    
    If WScript.Arguments.Count = 0 Then
      WScript.Echo "Specify Computer Name: "
      WScript.Quit
    End If
    
    Computer = WScript.Arguments(0)
    
    ' BEGIN CALLOUT A
    On Error Resume Next
    Set Registry = GetObject("winmgmts:{impersonationlevel=impersonate}!//" _
      & Computer & "/root/default:StdRegProv")
    If Err Then
      WScript.Echo Computer & vbTab & "Error 0x" & Hex(Err) _
        & " connecting to computer "
      WScript.Quit Err
    End If
    On Error GoTo 0
    ' END CALLOUT A
    
    ' BEGIN CALLOUT B
    Result = Registry.GetStringValue(HKEY_LOCAL_MACHINE, _
      "SOFTWARE\Network Associates\ePolicy Orchestrator\Agent", _
      "AgentGUID", AgentGUID)
    ' END CALLOUT B
    
    If Result = 0 Then
      WScript.Echo Computer & vbTab & AgentGUID
    Else
      WScript.Echo Computer & vbTab & "Error 0x" & Hex(Result) _
        & " reading Agent GUID"
    End If
    
    WScript.Quit Result
    I stick this vbs file into a directory called 'c:\scripts', along with a text file called 'computers.txt', then call the script from the following cmd file, piping the output to c:\scripts\results.csv - eg: GetAgentGUIDs.cmd >>c:\scripts\results.csv:

    Code:
    @Echo Off
    Setlocal Enableextensions
    For /f %%c In ('Type Computers.txt') Do (
      Cscript //Nologo GetAgentGUIDs.vbs %%c
    )
    Endlocal
    That should do the trick - I use it for pretty much everything I need to do along the lines of what you need it for. Can't remember where I got most of the code from, but it was probably the scripting guys (awesome scripting reference).

    HTH
     
    Last edited: Apr 25, 2010
    Certifications: A few
    WIP: None - f*** 'em
  4. Boycie
    Honorary Member

    Boycie Senior Beer Tester

    6,281
    85
    174
    Thanks for the replies Si and Zeb. Appreciated. Zeb: Just having a play with it now - thanks mate! :thumbleft
     
    Certifications: MCSA 2003, MCDST, A+, N+, CTT+, MCT
  5. Boycie
    Honorary Member

    Boycie Senior Beer Tester

    6,281
    85
    174
    Sorry for not replying about this sooner. I was about to use Zeb's idea when my colleague informed me our monitoring agent can do this with a few clicks although referenced this script as i know it will come in handy. :biggrin
     
    Certifications: MCSA 2003, MCDST, A+, N+, CTT+, MCT

Share This Page

Loading...