Read Registry on Remote Computer

  • Is there a way to read the registry on a remote computer?

    xp_regread does not appear to have a value for a remote computer.

  • 'xp_regread'  doesnt have optional arguments to provide remote access..... u can run an remote SP by linking other server to ur server..... the linked server concept..... ohhhhh iam making it a fuzzzzz...... iam not sure what u r trying to ask......

  • I have 30 machines running a client application and I want to read the registry on these machines and store some of the key values in a database. I was hoping to keep it simple and schedule a job several times a day keeping it all in tsql.

    Any suggestions?

  • Hi,

    You may try to use WMI objects to do that from VBscript.

    Yelena

    Regards,Yelena Varsha

  • Yelena,

    Do you by any chance have a .VBS example that will read the registry and stuff the info into either an Access or SQL database?  I'd be most interested.

    Thanks,


    Butch

  • Butch,

    I usually go to Microsoft Script center at

    http://www.microsoft.com/technet/scriptcenter/scripts/default.mspx

    There is a lot of great scripts. There click Operating System link and once there click Registry link. It will take you to:

    http://www.microsoft.com/technet/scriptcenter/scripts/os/registry/default.mspx

    From there you can select any example and use it as part of your code. Those are short code fragments that are easy to use. It contains the example for every kind of registry value, like binary, multistring and much more. It also has code for creating reg values. You may notice that code often contains the line:

    strComputer = "."

    Replace the dot with the actual computer name. Don't be confused with the line that contains GetObject. You have just copy and paste. I even did not try to understand the sytax for this line. Everything elase is self-explanatory.

    Do you know how to create a file using and write it or use ADO and write to table the registry values that you will be getting? For files use examples in

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/sgworkingwithfiles.asp

    Yelena

    Regards,Yelena Varsha

  • Yelena,

    I understand, and I have several scripts actually working, but I'm still new at this and I was looking for the piece that would add the records to a database.

    Thanks,


    Butch

  • Butch,

    Was a hard day yesterday, did not have time. If you find a ready to use script, please share with me. If you have to compose the script yourself after all, read below:

    It is difficult to write or recommend a script writing directly to the database without knowing you data and table structures and if data come from many sources you will spend a lot of time for debugging. If I personally have to do it really quick, I would use FileSystemObject, output results to the text file. I don't know if you are outputting just one value for each computer or many, but make it comma-separated for each computer. As step 2 create a DTS job to import this CSV file to SQL Server database. Suppose you alread use the examples from technet to get string values:

    ComputerName, RegValue1, Reg Value2

    To output these 3 values to the file use the script below.

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    ' Constants for opening files

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    Const OpenFileForReading = 1

    Const OpenFileForWriting = 2

    Const OpenFileForAppending = 8

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    ' Some handy global variables

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    Dim TabStop

    Dim NewLine

    NewLine = vbCrLf    ' Chr(13)&Chr(10)

    ' Creating FileSystemObject

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

        Dim fso

         Set fso = CreateObject("Scripting.FileSystemObject")

    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

        Dim CSVfilelist

        On Error Resume Next

     Set CSVfilelist = fso.CreateTextFile( "E:\" & "CSVfilelist.txt", True)

    ' Everything above this line have to be at the very beginning of the script

    ' Do it before the loop browsing compiters

    ' The next line should be within the loop

     CSVfilelist.WriteLine(ComputerName & "," & RegValue1 & "," & RegValue2)

    ' Everything below this line should be at the very end of the script

    ' Outside of the loop browsing computers 

    CSVfilelist.Close

    ' Do NOt fordet to set your objects to Nothing at the end like:

    Set FSO = Nothing

    Regards,Yelena Varsha

  • Yelena,

    Well, I finally figured it out.  I had the 'table name' misspelled!  What a bummer, but if you're still interested, here's the script:

    'ListApps.vbs

    ' by Butch Hoffman - 29-Jan-2005

    ' This script is designed to gather information about software installed on

    '  a client machine, using this script as part of a login script.

    ' Information is stored in either a local or network database, in this case

    '  called pcinfo.mdb.

    'Table name/structure:

    'Table: GWCSoftware                                                                                   Page: 1

    'Columns

    '

    ' Name   Type Size

    '

    ' ComputerName  Text  50

    ' Software  Text 100

    '

    ' Version   Text  30

    '

    'Table Indexes

    '

    ' Name   Number of Fields

    ' PrimaryKey  2

    '

    ' Fields: ComputerName Ascending

    '  Software Ascending

    '

    Option Explicit

    Dim strComputer, strKey, strSubKey

    Dim objRegistry

    Dim arrSubKeys()

    Dim strDisplayName, strDisplayVersion, strInstallLocation

    ' ********** Global Declarations **********

    Dim strComputerName  ' The Computer Name to be queried via WMI

    Dim strWinMgt  ' The WMI management String

    Dim objCon  ' A Connection Object for database connectivity

    Dim objRS  ' A Recordset Object for database connectivity

    Dim sProviderName ' The OLE Provider Type

    Dim iCursorType  ' The Cursor Type for the Recordset

    Dim iLockType  ' The Lock Type for the Recordset

    Dim sDataSource  ' The name and location of the database

    Dim intRam  ' The amount of RAM in the computer. 

    Dim CompSysSet  

    Dim CompSys

    Dim strName, ComputerName, strCriteria

    strComputerName = "."

    strWinMgt = "winmgmts://" & strComputerName &""

    ' Get Computername

        Set CompSysSet = GetObject(strWinMgt).ExecQuery("select * from Win32_ComputerSystem")

        For Each CompSys In CompSysSet

                ComputerName = CompSys.Name

        Next

    Const HKEY_LOCAL_MACHINE = &H80000002

    strComputer = "."

    strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"

    '*********************************************************************

    '* CALLOUT A

    '*********************************************************************

    Set objRegistry = GetObject("winmgmts:"   & _

        "{impersonationLevel=Impersonate}!\\" & _

        strComputer & "\root\default:StdRegProv")

    '*********************************************************************

    '* CALLOUT B

    '*********************************************************************

    objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKey, arrSubKeys

    Call subConnectionOpen

       strCriteria = "ComputerName = '"& ComputerName &"'"

       objRS.Find strCriteria

    If objRS.EOF Then

     Call subGetSw

     

    Else

     

            Call subDeleteRecord

            Call subGetSw

     

    End If

    Call subConnectionClose

    '*********************************************************************

    '* CALLOUT C

    '*********************************************************************

    Sub subGetSw

    On Error Resume Next

    For Each strSubKey In arrSubKeys

        objRegistry.GetStringValue HKEY_LOCAL_MACHINE, _

                                   strKey & "\" & strSubKey, _

                                   "DisplayName", _

        strDisplayName

        objRegistry.GetStringValue HKEY_LOCAL_MACHINE, _

                                   strKey & "\" & strSubKey, _

                                   "DisplayVersion", _

                                   strDisplayVersion

    ' Don't care about this particular value

    '    objRegistry.GetStringValue HKEY_LOCAL_MACHINE, _

    '                               strKey & "\" & strSubKey, _

    '                               "InstallLocation", _

    '                               strInstallLocation

    ' Uncomment the next 8 single (') commented lines to echo to the screen

    '  Uncomment the above registery key if you want to uncomment the double ('')

    '   commented line

    '

    '     WScript.Echo strSubKey

    '     WScript.Echo String(Len(strSubKey), "-")

    'If strDisplayName <> "" Then

    '     WScript.Echo "Computer Name:    " & ComputerName

    '     WScript.Echo "Display name:     " & strDisplayName

    '     WScript.Echo "Display version:  " & strDisplayVersion

    ''     WScript.Echo "Install location: " & strInstallLocation

    'End If

     If strDisplayName <> "" Then

      objRS.AddNew

      objRS("ComputerName") = LTrim(RTrim(ComputerName))

      objRS("Software") = LTrim(RTrim(strDisplayName))

      objRS("Version") = LTrim(RTrim(strDisplayVersion))

      objRS.Update

     End If

        strDisplayName = vbEmpty

        strDisplayVersion = vbEmpty

        strInstallLocation = vbEmpty

    Next

    End Sub

    '********** Beginning of Sub routine to Open database **********

    Sub subConnectionOpen

        Set objCon = CreateObject("ADODB.Connection")

        Set objRS = CreateObject("ADODB.Recordset")

        sProviderName        = "Microsoft.Jet.OLEDB.4.0"

        iCursorType          = 1

        iLockType            = 3

    'Network or Local File

    '    sDataSource          = "\\Gwfs4\Shares\GWCComputers\pcinfo.mdb"

        sDataSource          = "C:\DownLoad\ADS\VBScripts\pcinfo.mdb"

        objCon.Provider = sProviderName

        objCon.Properties("Data Source") = sDataSource

        objCon.Open

        objRS.CursorType = iCursorType

        objRS.LockType = iLockType

        objRS.Source = "GWCSoftware" '''Table name to open

        objRS.ActiveConnection = objCon

        objRS.Open

    End Sub

    '********** End of sub routine to Open database **********

    '********** Beginning of Sub routine to Close database **********

    Sub subConnectionClose

        Set objRS = Nothing

        Set objCon = Nothing

    End Sub

    '********** End of Sub routine to Close database **********

    '********** Beginning of Sub routine to delete record **********

    Sub subDeleteRecord

    ' Since we have one record per software instance, we don't want

    '  duplicates, so delete them all and reload them.

     Do Until objRS.EOF

      objRS.Find strCriteria

      objRS.Delete

      objRS.Update

      objRS.Requery

     Loop

    End Sub

    '********** End of Sub routine to delete record **********


    Butch

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply