Announcement

Collapse
No announcement yet.

VBScript - HKEY_USERS keys

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • VBScript - HKEY_USERS keys

    I am trying to read the Internet Settings for the currently logged in user on a remote machine. The code to get the user and the SID is complete but I can't seem to be able to get the keys

    It bombs our on the For Each line with a 'object not a collection' error.
    VarType(arrSubKeys) is returning a 1 (Null)

    I used an almost identical loop to obtain the SID so I believe the code is close

    Code:
    Private Function getProxyMode(strComputer, strSIDName)
        Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
        strKeyPath = strSIDvalue & "\Software\Microsoft\Windows\CurrentVersion\Internet Setting"
        objReg.EnumKey HKEY_USERS, strKeyPath, arrSubkeys
        For Each objSubkey In arrSubkeys
            strValueName = "ProxyEnable"
            strSubPath = strKeyPath & "\" & objSubkey
            objReg.GetExpandedDWordValue HKEY_USERS,strSubPath,strValueName,strValue
            WScript.Echo strValue
        Next 
    End Function

  • #2
    Re: VBScript - HKEY_USERS keys

    What if you make it a string instead of an object? Will it work?

    Code:
    Private Function getProxyMode(strComputer, strSIDName)
        Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
        strKeyPath = strSIDvalue & "\Software\Microsoft\Windows\CurrentVersion\Internet Setting"
        objReg.EnumKey HKEY_USERS, strKeyPath, arrSubkeys
        For Each strSubkey In arrSubkeys
            strValueName = "ProxyEnable"
            strSubPath = strKeyPath & "\" & strSubkey
            objReg.GetExpandedDWordValue HKEY_USERS,strSubPath,strValueName,strValue
            WScript.Echo strValue
        Next 
    End Function

    Comment


    • #3
      Re: VBScript - HKEY_USERS keys

      Originally posted by ekrengel View Post
      What if you make it a string instead of an object? Will it work?
      You lost me. I thought vbscript was a typeless language or more exactly, all variable types are variants until they are assigned a value. So, the result of the objReg.EnumKey would become whatever it was populated as. In all the examples I have found this is an array.

      If I use a varType() on the arrSubKeys variable after the EnumKey call it is of type null. I am thinking there is an issue with the way I am attempting to read the hive/keys/values.

      Of course I could be way off base.

      Ed

      Comment


      • #4
        Re: VBScript - HKEY_USERS keys

        Yes that's true actually. Sorry my bad. I was looking at some other scripts that I had that I thought were working...but I am having a simliar problem to you with not enumerating subkeys. I was trying something like this:

        Code:
        For Each Path in strKeyPaths
           If RegKeyExists(HKLM, Path, strValueName) Then
              objregService.EnumKey HKLM, Path, arrSubkeys
              If IsArray(arrSubkeys) Then
                 For Each strSubkey In arrSubkeys
        	    If (Left(strSubkey,InStr(strSubkey, "tm")) - 2) _
        	    	OR (Left(strSubkey,InStr(strSubkey, "ntr")) - 3) _
        		OR (Left(strSubkey,InStr(strSubkey, "vsa")) - 3) _
        		OR (Left(strSubkey,InStr(strSubkey, "off")) - 3) Then
                       DeleteSubkeys HKLM, Path & "\" & strSubkey
        	       KeysDeleted = KeysDeleted + 1
        	    End If
                 Next
              End If
           End If
        Next
        Mine is pretty much the same as yours, I just have some other error checking in place to see if its an arrary or if the key actually exists. But my error comes when checking the string...different from yours. Not that this actually helps you

        Comment


        • #5
          Re: VBScript - HKEY_USERS keys

          Originally posted by edpatterson View Post
          I thought vbscript was a typeless language

          You have understood VBScript's variants - which really suck - correctly.

          Too bad the MSDN examples you've obviously been looking at do not work. So try the code beneath. Take a peek at working stuff.

          Try this to get the value you wish:
          Code:
          Private Function getProxyMode(strComputer, strSIDName)
              Const HKEY_USERS = &H80000003
              
              Set objReg = GetObject("winmgmts:\\" & strComputer &_
           "\root\default:StdRegProv")
              strKeyPath = strSIDName &_
           "\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
              strValueName = "ProxyEnable"
              
              objReg.GetDWORDValue HKEY_USERS, strKeyPath, strValuename, dwValue
              wscript.echo dwValue
          End Function
          I tuned up some example code to tell you more about registry. Have fun.
          Code:
          sub getpx(strComputer, strSID)
              const REG_SZ = 1
              const REG_EXPAND_SZ = 2
              const REG_BINARY = 3
              const REG_DWORD = 4
              const REG_MULTI_SZ = 7
              Const HKEY_USERS = &H80000003
              Set StdOut = WScript.StdOut
          
              Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
           strComputer & "\root\default:StdRegProv")
          
              strKeyPath = strSID &_
           "\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
          
              oReg.EnumValues HKEY_USERS, strKeyPath, arrValueNames, arrValueTypes
          
              For i=0 To UBound(arrValueNames)
                  StdOut.WriteLine "Value Name: " & arrValueNames(i) 
                  
                  Select Case arrValueTypes(i)
                      Case REG_SZ
                          StdOut.WriteLine "Data Type: String"
                          oReg.GetStringValue HKEY_USERS, strKeyPath,_
           arrValueNames(i) , val
                          stdout.writeline val
                          StdOut.WriteBlankLines(1)
                      Case REG_EXPAND_SZ
                          StdOut.WriteLine "Data Type: Expanded String"
                          oReg.GetExpandedStringValue HKEY_USERS, strKeyPath,_
           arrValueNames(i) , val
                          stdout.writeline val
                          StdOut.WriteBlankLines(1)
                      Case REG_BINARY
                          StdOut.WriteLine "Data Type: Binary"
                          oReg.GetBinaryValue HKEY_USERS, strKeyPath,_
           arrValueNames(i) , val
                          stdout.writeline join(val)
                          StdOut.WriteBlankLines(1)
                      Case REG_DWORD
                          StdOut.WriteLine "Data Type: DWORD"
                          oReg.GetDWORDValue HKEY_USERS, strKeyPath,_
           arrValueNames(i) , val
                          stdout.writeline val
                          StdOut.WriteBlankLines(1)
                      Case REG_MULTI_SZ
                          StdOut.WriteLine "Data Type: Multi String"
                          oReg.GetMultiStringValue HKEY_USERS, strKeyPath,_
           arrValueNames(i) , val
                          stdout.writeline val
                          StdOut.WriteBlankLines(1)
                  End Select 
              Next
          end sub
          -vP
          Last edited by vonPryz; 14th December 2009, 21:19. Reason: Fixed code formating a bit.

          Comment

          Working...
          X