Need help please, need to finish script by today

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

  1. Amador

    Amador Guest

    Hello All.
    I somewhat put this script together to enumerate ODBC entries on a group of
    machine. Now while I'm able to enumerate the subkeys under
    HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI will like to also enumerate the
    values under the subkeys. Can anyone help. Below I posted the script I put
    together.

    On Error Resume Next

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

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

    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


    strKeyPath = "SOFTWARE\ODBC\ODBC.INI"
    oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

    For Each subkey In arrSubKeys
    objLog.WriteLine subkey

    Next
    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"
    'bjLog.WriteBlankLines(1)
    Case REG_EXPAND_SZ
    objLog.WriteLine "Data Type: Expanded String"
    'bjLog.WriteBlankLines(1)
    Case REG_BINARY
    objLog.WriteLine "Data Type: Binary"
    'bjLog.WriteBlankLines(1)
    Case REG_DWORD
    objLog.WriteLine "Data Type: DWORD"
    'objLog.WriteBlankLines(1)
    Case REG_MULTI_SZ
    objLog.WriteLine "Data Type: Multi String"
    End Select
    Next
    objLog.WriteBlankLines (1)
    Loop
    objLog.WriteLine vbNewLine & "Audit finished: " & Date & " " & Time &
    vbNewLine & vbNewLine
    objFile.Close
    objLog.Close
    MsgBox "Scripting is done running"

    Please post here or e-mail me at
     
    Amador, Oct 23, 2003
    #1
    1. Advertisements

  2. Hi

    Here is a VBScript/WMI example that walks a registry branch echoing all keys.
    The third parameter (Boolean True/False) to the sub EnumRegistryKey will
    determine if the sub is to stop at first level or traverse the complete tree:


    Const HKLM = &H80000002
    sKey = "SOFTWARE\ODBC\ODBC.INI"

    Set oReg = GetObject _
    ("WinMgmts:{impersonationLevel=impersonate}!//./root/default:StdRegProv")

    EnumRegistryKey HKLM, sKey, True


    Sub EnumRegistryKey(hive, key, DeepTraversal)
    oReg.EnumKey hive, key, arSubKeys
    For Each key2 In arSubKeys
    WScript.Echo key & "\" & key2
    If DeepTraversal Then
    EnumRegistryKey hive, key & "\" & key2, True
    End If
    Next
    End Sub
     
    Torgeir Bakken (MVP), Oct 23, 2003
    #2
    1. Advertisements

  3. Amador

    Amador Guest

    I recevied this error. from this line

    For Each key2 In arSubKeys


    error: Object not a collection
     
    Amador, Oct 23, 2003
    #3
  4. Hi

    Try this one instead:

    Const HKLM = &H80000002
    sKey = "SOFTWARE\ODBC\ODBC.INI"

    Set oReg = GetObject _
    ("WinMgmts:{impersonationLevel=impersonate}!//./root/default:StdRegProv")

    EnumRegistryKey HKLM, sKey, True


    Sub EnumRegistryKey(hive, key, DeepTraversal)
    On Error Resume Next
    oReg.EnumKey hive, key, arSubKeys
    For Each key2 In arSubKeys
    If Err.Number <> 0 Then
    Err.Clear
    Exit Sub
    End If
    WScript.Echo key & "\" & key2
    If DeepTraversal Then
    EnumRegistryKey hive, key & "\" & key2, True
    End If
    Next
    End Sub
     
    Torgeir Bakken (MVP), Oct 23, 2003
    #4
  5. Amador

    Amador Guest

    This enumerates active subkeys under a subkey, what I was looking for is to
    enumerate every ODBC entry under ODBC.ini and also enumerate the value under
    each entry.

    For Example
    ODBC Entry = testdb
    Database name
    Description
    Driver
    LastUser
    Server

    So what I need is to enumerate all the values under each odbc entry under
    ODBC.ini.

    Thanks for all your help.
     
    Amador, Oct 24, 2003
    #5
  6. Hi

    Run this script in a command prompt with cscript.exe and see if it is what you
    want:


    Const HKLM = &H80000002
    Const REG_SZ = 1
    Const REG_EXPAND_SZ = 2
    Const REG_BINARY = 3
    Const REG_DWORD = 4
    Const REG_MULTI_SZ = 7


    sKey = "SOFTWARE\ODBC\ODBC.INI"

    Set oReg = GetObject _
    ("WinMgmts:{impersonationLevel=impersonate}!//./root/default:StdRegProv")

    EnumRegistryKey HKLM, sKey, False


    Sub EnumRegistryKey(hive, key, DeepTraversal)
    On Error Resume Next
    oReg.EnumKey hive, key, arSubKeys
    For Each key2 In arSubKeys
    If Err.Number <> 0 Then
    Err.Clear
    Exit Sub
    End If
    On Error Goto 0
    EnumRegistyValues hive, key & "\" & key2
    If DeepTraversal Then
    EnumRegistryKey hive, key & "\" & key2, True
    End If
    On Error Resume Next
    Next
    End Sub


    Sub EnumRegistyValues(iHive, sKey)
    WScript.Echo
    WScript.Echo "Key: " & sKey
    oReg.EnumValues iHive, sKey, aValueNames, aValueTypes
    For i = 0 To UBound(aValueNames)
    WScript.Echo
    WScript.Echo "Value Name: " & aValueNames(i)
    Select Case aValueTypes(i)
    Case REG_SZ
    oReg.GetStringValue iHive, sKey, aValueNames(i), sValue
    WScript.Echo "Value Data: " & sValue

    Case REG_EXPAND_SZ
    oReg.GetExpandedStringValue iHive, sKey, aValueNames(i), sValue
    WScript.Echo "Value Data: " & sValue

    Case REG_DWORD
    oReg.GetDWORDValue iHive, sKey, aValueNames(i), iValue
    WScript.Echo "Value Data: " & iValue
    End Select
    Next
    End Sub
     
    Torgeir Bakken (MVP), Oct 24, 2003
    #6
  7. Amador

    Amador Guest

    Is there anyway I could run this to a machine remotelly. I try running this
    with reading this from a pclist and writing the values to a log but I keep
    getting errors from this line. Sub EnumRegistryKey(hive, key,
    DeepTraversal) compilation error:

    Here is my script below

    Const HKLM = &H80000002
    Const REG_SZ = 1
    Const REG_EXPAND_SZ = 2
    Const REG_BINARY = 3
    Const REG_DWORD = 4
    Const REG_MULTI_SZ = 7
    Const ForWriting = 2, ForReading = 1

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

    Do While objFile.AtEndofStream = False
    strComputer = objFile.ReadLine
    WScript.Echo "Reading Computer: " &strComputer
    'strComputer = InputBox ("Enter Computer Name",".")

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

    sKey = "SOFTWARE\ODBC\ODBC.INI"

    EnumRegistryKey HKLM, sKey, False


    Sub EnumRegistryKey(hive, key, DeepTraversal)
    On Error Resume Next
    oReg.EnumKey hive, key, arSubKeys
    For Each key2 In arSubKeys
    If Err.Number <> 0 Then
    Err.Clear
    Exit Sub
    End If
    On Error Goto 0
    EnumRegistyValues hive, key & "\" & key2
    If DeepTraversal Then
    EnumRegistryKey hive, key & "\" & key2, True
    End If
    On Error Resume Next
    Next
    End Sub


    Sub EnumRegistyValues(iHive, sKey)
    WScript.Echo
    objLog.WriteLine "Key: " & sKey
    oReg.EnumValues iHive, sKey, aValueNames, aValueTypes
    For i = 0 To UBound(aValueNames)
    WScript.Echo
    objLog.WriteLine "Value Name: " & aValueNames(i)
    Select Case aValueTypes(i)
    Case REG_SZ
    oReg.GetStringValue iHive, sKey, aValueNames(i), sValue
    objLog.WriteLine "Value Data: " & sValue

    Case REG_EXPAND_SZ
    oReg.GetExpandedStringValue iHive, sKey, aValueNames(i), sValue
    objLog.WriteLine "Value Data: " & sValue

    Case REG_DWORD
    oReg.GetDWORDValue iHive, sKey, aValueNames(i), iValue
    objLog.WriteLine "Value Data: " & iValue
    End Select
    Next
    End Sub
    Next
    objLog.WriteBlankLines (1)
    Loop
    objLog.WriteLine vbNewLine & "Audit finished: " & Date & " " & Time &
    vbNewLine & vbNewLine
    objFile.Close
    objLog.Close
    MsgBox "Scripting is done running"
     
    Amador, Oct 24, 2003
    #7
    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.