Source language: Translate to:

VBS function: Read Registry Keys and Values

Questions and information about using VBScript and JavaScript in NeoBook functions

Moderator: Neosoft Support

VBS function: Read Registry Keys and Values

Postby dpayer » Wed Mar 21, 2012 2:53 pm

I have adapted several scripts into one NB function which will read registry subkeys of the top level registry folders and key values within those subkeys. The original work came was inspired by the MSDN site but I got my start from scripts on this site:

http://www.activexperts.com/activmonito ... egVals.htm

This function will write the list of subkeys to an NB varaible array. It does the same for a list of key values of the selected key. I have created a sample application that uses the function and you are free to use this as a base for your own work. It is created with only NB native functions (no plugins) together with the VBS function. You can drill down to lower levels by double clicking on the keys. You can also enter a known key and click the search button to get results.
Image

This function will read even binary data but VBS does not have different types of variables so it evaluates hex numbers (turning 00 into 0 or 02 into 2) before you can convert this number to a string with a VBS function.

I do not attempt getting registry entries that are complex arrays of binary data. Here are the types not obtained:

REG_DWORD_BIG_ENDIAN
REG_LINK
REG_RESOURCE_LIST
REG_FULL_RESOURCE_DESCRIPTOR
REG_RESOURCE_REQUIREMENTS_LIST
REG_QWORD

But it is possible to update the function so these keys will display their names and the type of key they are, but no data.

Also, this script takes a LOOOOOONNNNNG time to get all entries from the HKEY_CLASSES_ROOT folder.

The lists of keys and data are exposed as variables so you should be able to adapt this to any work you would use this for. The app copies the lists to the clipboard.

Enjoy! Comments are welcome.

David Payer

Here are links:

NB pub file for the registry reader
Compiled exe: registryreader.exe
This is the VBS function named: Registry_Enumerate_SubKeys in the app

There are two variables you submit to the function. The top level registry folder and the key path you are searching. Note: you will need to convert the top level registry name to a number before submitting. See the comment when you do the function call.

Here is the function itself (don't forget to remove the space at the end of each line caused by this forum software before saving this as a function):

Code: Select all
{NeoBook Function}
Version=5.70
Language=VBScript
Comment=returns list of registry subkeys via array: regsubkey
Param=[%1]|Variable|variable : HKCR=0; HKCU=1; HKLM=2; HKU=3; HKCC=5
Param=[%2]|Variable|contains the registry path under chosen top level folder
{End}
Dim tlrfolder
tlrfolder = publication.nbGetVar ("[%1]")

'MsgBox ( tlrfolder )

const HKEY_CLASSES_ROOT = &H80000000
const HKEY_CURRENT_USER = &H80000001
const HKEY_LOCAL_MACHINE = &H80000002
const HKEY_USERS = &H80000003
const HKEY_CURRENT_CONFIG = &H80000005
'Const HKEY_DYN_DATA                  = &H80000006 ' Windows 95/98 only
Const REG_SZ                         =  1
Const REG_EXPAND_SZ                  =  2
Const REG_BINARY                     =  3
Const REG_DWORD                      =  4
'Const REG_DWORD_BIG_ENDIAN           =  5
'Const REG_LINK                       =  6
Const REG_MULTI_SZ                   =  7
'Const REG_RESOURCE_LIST              =  8
'Const REG_FULL_RESOURCE_DESCRIPTOR   =  9
'Const REG_RESOURCE_REQUIREMENTS_LIST = 10
'Const REG_QWORD                      = 11
'only have cases for 1,2,3,4,7 so far

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

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&_
    strComputer & "\root\default:StdRegProv")
Dim strKeyPath
strKeyPath = publication.nbGetVar ("[%2]")
'MsgBox (strKeyPath )

Select Case tlrfolder

   Case 0
   objReg.EnumKey HKEY_CLASSES_ROOT, strKeyPath, arrSubKeys
    oReg.EnumValues HKEY_CLASSES_ROOT, strKeyPath,_
 arrValueNames, arrValueTypes
    tlr = &H80000000
   Case 1
   objReg.EnumKey HKEY_CURRENT_USER, strKeyPath, arrSubKeys
   oReg.EnumValues HKEY_CURRENT_USER, strKeyPath,_
 arrValueNames, arrValueTypes
    tlr= &H80000001
   Case 2
   objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
    oReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath,_
 arrValueNames, arrValueTypes
    tlr = &H80000002
   Case 3
   objReg.EnumKey HKEY_USERS, strKeyPath, arrSubKeys
    oReg.EnumValues HKEY_USERS, strKeyPath,_
 arrValueNames, arrValueTypes
    tlr = &H80000003
   Case 5
   objReg.EnumKey HKEY_CURRENT_CONFIG, strKeyPath, arrSubKeys
   oReg.EnumValues HKEY_CURRENT_CONFIG, strKeyPath,_
 arrValueNames, arrValueTypes
     tlr = &H80000005

End Select

If IsNull(arrSubKeys) Then
    publication.nbSetVar "[regsubkey]", "nosubkey"
Else

   i=1
  For Each SubXKey In arrSubKeys

    publication.nbSetVar "[regsubkey"&i&"]", SubXKey

   ' MsgBox ( SubXKey )
    i=i+1
  Next
End if

If IsNull(arrValueNames) Then
    publication.nbSetVar "[regkeyvalue]", "noregistrykeyvalues"
 '   MsgBox ( "No registry key values found" )
Else
announcelen = uBound(arrValueNames)
'MsgBox ( announcelen & "values found" )
For i=0 To UBound(arrValueNames)
  KeyValueName = arrValueNames(i)
'MsgBox ( KeyValueName )
    Select Case arrValueTypes(i)
        Case REG_SZ
        KeyDataType = "REG_SZ"

    oReg.GetExpandedStringValue tlr,strKeyPath,_
   KeyValueName,strValue

        Case REG_EXPAND_SZ
        KeyDataType = "REG_EXPAND_SZ"


    oReg.GetExpandedStringValue tlr,strKeyPath,_
   KeyValueName,strValue

        Case REG_BINARY
        KeyDataType = "REG_BINARY"

    oReg.GetBinaryValue tlr,strKeyPath,_
    KeyValueName,strValue
        For z = lBound(strValue) to uBound(strValue)
        binstrval = binstrval & CStr(strValue(z)) & " "
         Next

    strvalue = binstrval

        Case REG_DWORD
        KeyDataType = "REG_WORD"

    oReg.GetDWORDValue tlr,strKeyPath,KeyValueName,dwValue
        strvalue = dwvalue

        Case REG_MULTI_SZ
        KeyDataType = "REG_MULTI_SZ"
         oReg.GetMultiStringValue tlr,strKeyPath,_
        KeyValueName,arrValues

        For Each partialstrValue In arrValues
        strValue = strvalue & partialstrValue
       Next

    End Select
    regvalueentry = (KeyValueName & Chr(34) & "," & Chr(34) & KeyDataType & Chr(34) & "," & Chr(34) & strValue)

'MsgBox (regvalueentry )
    publication.nbSetVar "[regkeyvalue"&i&"]", regvalueentry
Next
End if
set objReg = nothing
set oReg = nothing
User avatar
dpayer
 
Posts: 1380
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Postby Neosoft Support » Thu Mar 22, 2012 10:06 am

Thanks for sharing this with us!
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5593
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA

Postby CN_Iceman » Thu Mar 22, 2012 12:53 pm

Thank's!
Very interesting.
Greetings/Saludos, Jose.
www.icemansoft.es
User avatar
CN_Iceman
 
Posts: 297
Joined: Tue Mar 01, 2011 11:04 am
Location: España

Postby datadon » Thu Mar 22, 2012 1:23 pm

It's getting better and better every day!

Thanks a bunch.
Don

'If you want to get a brontosaurus from 'a' to 'b' then you ride the dinosaur - you don't carry it!'
User avatar
datadon
 
Posts: 389
Joined: Sun Apr 03, 2005 7:55 pm
Location: Lorena Texas

Postby chromebandit » Thu Mar 22, 2012 1:30 pm

Very nice work!

what do you think?- could it be posible to call dlls from vbs have you ever made a research for that?

Regards
User avatar
chromebandit
 
Posts: 283
Joined: Wed Nov 24, 2010 5:00 pm

Postby dpayer » Thu Mar 22, 2012 2:46 pm

chromebandit wrote:Very nice work!

what do you think?- could it be posible to call dlls from vbs have you ever made a research for that?

Regards


What I have found indicates you can create objects from DLLs that are registered but you have to know before hand their functions/methods.

I am still learning so I don't feel capable of that yet. I am trying several new things though and am finally starting to understand the syntax of VBS / JScript better and the doors it opens up.

Also, I realize that many plugins that we have in the NB toolbox can be matched with VBS / JScript functionality. I think if we all collaborate, we should be able to create a nice library here of scripts that enhance NB functions.

David P.
User avatar
dpayer
 
Posts: 1380
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Postby Tony Kroos » Thu Mar 22, 2012 7:53 pm

There are several types of DLL. If we talking about native win32 DLL (like system modules, neobook plugins), it is impossible to call dll functions by native vbscript and could be very tricky using third-party modules.
Only ActiveX-DLL (must be registered com object) can be handled in vbscript by CreateObject.

So, if you want to call native dll from vbscript you may forget about it.

dpayer wrote:Also, I realize that many plugins that we have in the NB toolbox can be matched with VBS / JScript functionality. I think if we all collaborate, we should be able to create a nice library here of scripts that enhance NB functions.
David P.

We could, but I think plugin devs won't be very happy to hear about it :D
Tony Kroos
 
Posts: 402
Joined: Thu Oct 15, 2009 3:43 pm

Postby chromebandit » Thu Mar 22, 2012 10:00 pm

I think vbs is nice for litle functions and we realy should make some kind of library - as David said we all benefit from it!

Plugins are needed anyway - for example what i cant do in vbs i try to do in delphi there is no workarround... what i cant do iam happy to buy as plugin if its available

Regards
User avatar
chromebandit
 
Posts: 283
Joined: Wed Nov 24, 2010 5:00 pm

Postby dpayer » Fri Mar 23, 2012 7:36 am

dpayer wrote:Also, I realize that many plugins that we have in the NB toolbox can be matched with VBS / JScript functionality. I think if we all collaborate, we should be able to create a nice library here of scripts that enhance NB functions.
David P.


Tony Kroos wrote:We could, but I think plugin devs won't be very happy to hear about it :D


Tony, there are clearly many things not possible via scripting alone and we have some very capable plugin developers here who I wish great success for. I think their efforts at creating what scripting cannot create will always be welcome.

My recent posts with samples of the little I have learned about the powers of vb / jscript are just a small way of returning my thanks to a generous community of developers here who have freely shared their knowledge with me. I don't think a library of sample scripts will hurt any of our serious plugin developers. In fact, their work ought to be appreciated all the more because they do what others cannot!

David
User avatar
dpayer
 
Posts: 1380
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA


Return to NeoBook Functions - VBScript & JavaScript

Who is online

Users browsing this forum: No registered users and 0 guests