Enumerate specific value in ODBC reg key

Discussion in 'Scripting' started by Amador, Oct 15, 2003.

  1. Amador

    Amador Guest

    Here is the scenario,
    We are currently migrating our SQL server, and we have numerous desktop with
    ODBC entries that are pointing to the old server. My task is to enumerate
    key hk_local_machine\Software\ODBC\ODBC.INI and look thru each ODBC entry
    and find a server name and if the server name is found I need to write to
    the file the computer name. I put this script together , but I'm still a
    newbie and dont understand some of the commands yet. So the goal is to
    enumerate ODBC.ini for a particular server value. right now I'm writing
    value that I dont need.

    Thanks in advance for your help

    const HKEY_LOCAL_MACHINE = &H80000002
    Const ForWriting = 2, ForReading = 1

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.OpenTextFile("c:\scripts\nyepclist.txt", ForReading,
    Set objLog = objFSO.OpenTextFile("C:\scripts\nyepclog.log", ForWriting,
    objLog.WriteLine "Audit started: " & Date & " " & Time

    Do While objFile.AtEndofStream = False
    strComputer = objFile.ReadLine
    WScript.Echo "Reading Computer: " &strComputer

    'strComputer = "."
    Set StdOut = WScript.StdOut

    Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
    strComputer & "\root\default:StdRegProv")
    objLog.WriteLine strComputer

    strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
    strValueName = "DefaultUserName"
    oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
    objLog.WriteLine "Logon User Name: " & strValue

    oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

    For Each subkey In arrSubKeys
    objLog.WriteLine subkey

    objLog.WriteBlankLines 1

    strKeyPath = "Software\ODBC\ODBC.INI\ODBC Data Sources"

    oReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath,_
    arrValueNames, arrValueTypes
    objLog.WriteLine "ODBC DATA SOURCES"
    For i=0 To UBound(arrValueNames)
    objLog.WriteLine "Value Name: " & arrValueNames(i)

    Select Case arrValueTypes(i)
    Case REG_SZ
    objLog.WriteLine "Data Type: String"
    objLog.WriteLine "Data Type: Expanded String"
    objLog.WriteLine "Data Type: Binary"
    Case REG_DWORD
    objLog.WriteLine "Data Type: DWORD"
    objLog.WriteLine "Data Type: Multi String"
    End Select
    objLog.WriteBlankLines (1)
    objLog.WriteLine vbNewLine & "Audit finished: " & Date & " " & Time &
    vbNewLine & vbNewLine
    Amador, Oct 15, 2003
    1. Advertisements

  2. Hi

    See here for an alternative way to do it:

    Torgeir Bakken (MVP), Oct 15, 2003
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.