Script to Enumerate Cached Exchange mode usage

Discussion in 'Scripting & Programming' started by zebulebu, Jan 29, 2008.

  1. zebulebu

    zebulebu Terabyte Poster

    3,748
    330
    187
    Hi scripting bods.

    I've created a script to enumerate the values within a registry key that shows whether or not Cached Exchange mode is enabled on a particular workstation. The script runs fine for the first value in the key but doesn't seem to loop properly. When run I get the following error:

    Error: The handle is invalid.
    Code: 80070006

    The error occurs at Line 32, Char 2 - highlighted in the script below. This script has been adapted from the one at this link and is pretty basic but my scripting knowledge is pants (too much like programming for me :)) and I can't see what's wrong. I've fixed a typo on the original at line 25 (missing comma).

    Here's the script:

    Code:
    Const HKEY_CURRENT_USER = &H80000001
    Const REG_SZ = 1
    Const REG_EXPAND_SZ = 2
    Const REG_BINARY = 3
    Const REG_DWORD = 4
    Const REG_MULTI_SZ = 7
    
    strComputer = "."
    Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
     strComputer & "\root\default:StdRegProv")
    strKeyPath = "Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\13dbb0c8aa05101a9bb000aa002fc45a"
    objReg.EnumValues HKEY_CURRENT_USER,_
     strKeyPath,arrEntryNames,arrValueTypes
     
    For i=0 To UBound(arrEntryNames)
     Wscript.Echo "Entry Name: " & arrEntryNames(i)
     Select Case arrValueTypes(i)
     Case REG_SZ
     Wscript.Echo "Data Type: String"
     objReg.GetStringValue HKEY_CURRENT_USER, _
     strKeyPath, arrEntryNames(i),strValue
     Wscript.Echo "Value: " & strValue
     Case REG_EXPAND_SZ
     Wscript.Echo "Data Type: Expanded String"
     objReg.GetExpandedStringValue HKEY_CURRENT_USER, _
     strKeyPath, arrEntryNames(i),estrValue
     Wscript.Echo "Value: " & estrValue
     Case REG_BINARY
     Wscript.Echo "Data Type: Binary"
     objReg.GetBinaryValue HKEY_CURRENT_USER, _
     strKeyPath, arrEntryNames(i),arrValue
     WScript.StdOut.Write "Value: "
     For Each byteValue in arrValue
     WScript.StdOut.Write byteValue & " "
     Next
     WScript.StdOut.Write vbCRLF
     Case REG_DWORD
     Wscript.Echo "Data Type: DWORD"
     objReg.GetDWORDValue HKEY_CURRENT_USER, _
     strKeyPath, arrEntryNames(i),dwValue
     Wscript.Echo "Value: " & dwValue
     Case REG_MULTI_SZ
     Wscript.Echo "Data Type: Multi String"
     objReg.GetMultiStringValue HKEY_CURRENT_USER, _
     strKeyPath, arrEntryNames(i),arrValues
     For Each strValue in arrValues
     Wscript.Echo strValue
     Next
     End Select
    Next
    Any help would be greatly appreciated, as otherwise it means traipsing round 200-odd workstations doing a manual check

    Cheers :biggrin
     
    Certifications: A few
    WIP: None - f*** 'em
  2. Stoney

    Stoney Megabyte Poster

    731
    23
    69
    I think your problem is that you haven't declared an instance of 'wscript.stdout'

    Try adding

    Set objStdOut = WScript.StdOut

    at the start of the script where you declare your variables.

    then when you need to use WScript.StdOut use 'objStdOut.Write' instead.

    HTH
     
    Certifications: 25 + 50 metre front crawl
    WIP: MCSA - Exam 70-270
  3. zebulebu

    zebulebu Terabyte Poster

    3,748
    330
    187
    Stoney

    Thanks - I've made the change as suggested, but am now getting the same error at line 33. Looks like the change has enabled the script to get beyond line 32 but it hangs at the next line now.

    Here's the modified script:

    Code:
    Const HKEY_CURRENT_USER = &H80000001
    Const REG_SZ = 1
    Const REG_EXPAND_SZ = 2
    Const REG_BINARY = 3
    Const REG_DWORD = 4
    Const REG_MULTI_SZ = 7
    
    strComputer = "."
    Set objStdOut = WScript.StdOut
    
    Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
     strComputer & "\root\default:StdRegProv")
    strKeyPath = "Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\13dbb0c8aa05101a9bb000aa002fc45a"
    objReg.EnumValues HKEY_CURRENT_USER,_
     strKeyPath,arrEntryNames,arrValueTypes
     
    For i=0 To UBound(arrEntryNames)
     Wscript.Echo "Entry Name: " & arrEntryNames(i)
     Select Case arrValueTypes(i)
     Case REG_SZ
     Wscript.Echo "Data Type: String"
     objReg.GetStringValue HKEY_CURRENT_USER, _
     strKeyPath, arrEntryNames(i),strValue
     Wscript.Echo "Value: " & strValue
     Case REG_EXPAND_SZ
     Wscript.Echo "Data Type: Expanded String"
     objReg.GetExpandedStringValue HKEY_CURRENT_USER, _
     strKeyPath, arrEntryNames(i),estrValue
     Wscript.Echo "Value: " & estrValue
     Case REG_BINARY
     Wscript.Echo "Data Type: Binary"
     objReg.GetBinaryValue HKEY_CURRENT_USER, _
     strKeyPath, arrEntryNames(i),arrValue
     objStdOut.Write "Value: "
     For Each byteValue in arrValue
     objStdOut.Write byteValue & " "
     Next
     objStdOut.Write vbCRLF
     Case REG_DWORD
     Wscript.Echo "Data Type: DWORD"
     objReg.GetDWORDValue HKEY_CURRENT_USER, _
     strKeyPath, arrEntryNames(i),dwValue
     Wscript.Echo "Value: " & dwValue
     Case REG_MULTI_SZ
     Wscript.Echo "Data Type: Multi String"
     objReg.GetMultiStringValue HKEY_CURRENT_USER, _
     strKeyPath, arrEntryNames(i),arrValues
     For Each strValue in arrValues
     Wscript.Echo strValue
     Next
     End Select
    Next
     
    Certifications: A few
    WIP: None - f*** 'em
  4. Stoney

    Stoney Megabyte Poster

    731
    23
    69
    Possibly there's no spaces either side of the = in

    Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
     
    Certifications: 25 + 50 metre front crawl
    WIP: MCSA - Exam 70-270
  5. Sparky
    Highly Decorated Member Award 500 Likes Award

    Sparky Zettabyte Poster Moderator

    10,718
    543
    364
    Certifications: MSc MCSE MCSA:M MCSA:S MCITP:EA MCTS(x5) MS-900 AZ-900 Security+ Network+ A+
    WIP: Microsoft Certs
  6. zebulebu

    zebulebu Terabyte Poster

    3,748
    330
    187
    Cheersd Stoney, I've tried that and it had no effect. Not to worry, I've run a manual check on all of them now by remotely interrogating the registry on each machine. Took about 20 minutes, but faster than trying to sod around and get the script working!

    Sparky - I'm not going to deploy any changes - I just wanted to see how many clients had been set up to use CE for some reporting that I'm running. If we need to make the change I've got the GPO ready to go already - I did it once before at a job a couple of years ago.
     
    Certifications: A few
    WIP: None - f*** 'em

Share This Page

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.