' ---------------------------------------------------------------------------------------------------------------- ' REGISTRY access using WMI Wbemscripting ' ---------------------------------------------------------------------------------------------------------------- newscript ' ---------------------------------------------------------- there are three eexample, select the one you want to run 1,2,3 dim SelectExample = 1 ' ---------------------------------------------------------- ' ---------------------------------------------------------------------------------------------------------------- ' Useful functions for displaying the input & output ' ---------------------------------------------------------------------------------------------------------------- FUNCTION DisplayTrigger ( inParams , useMethod ) dim tmp = inparams.properties_.item("Hdefkey").Value freestring = "Request: """ IF ( tmp == HKCR ) then freestring = freestring & "HKEY_CLASSES_ROOT" ELSEIF ( tmp == HKCU ) then freestring = freestring & "HKEY_CURRENT_USER" ELSEIF ( tmp == HKLM ) then freestring = freestring & "HKEY_LOCAL_MACHINE" ELSEIF ( tmp == HKU ) then freestring = freestring & "HKEY_USERS" ELSEIF ( tmp == HKCC ) then freestring = freestring & "HKEY_CURRENT_CONFIG" ELSE freestring = freestring & "????" END if freestring = freestring & "\\" & inparams.properties_.item("sSubKeyName").Value IF ( useMethod ="GetStringValue" ) then freestring = freestring & "\\" & inparams.properties_.item("Svaluename").Value END If message = freestring END Function ' ---------------------------------------------------------------------------------------------------------------- FUNCTION DisplayResponse ( outParams , useMethod ) dim lvRow, index sob (soblv, "empty") IF ( Outparams.returnValue ) then Message = " Failure: Return code = " & Outparams.returnValue STOP END IF ' the entire (I think) response is visible using: message = Outparams.GetObjectText_ ' warning need whitespace after the underscore, is NOT a line continuation underscore IF ( useMethod == "EnumValues" ) then dim nameArray = Outparams . snames dim typeArray = Outparams . types dim tkarr = split ( "REG_SZ,REG_EXPAND_SZ,REG_BINARY,REG_DWORD,REG_DWORD_BIG_ENDIAN,REG_LINK,REG_MULTI_SZ,REG_RESOURCE_LIST,REG_FULL_RESOURCE_DESCRIPTOR,REG_RESOURCE_REQUIREMENTS_LIST,REG_QWORD",",") IF instr ( istype(nameArray ), "arr") then sob (soblv, "add" , "column", "Name") sob (soblv, "add" , "column", "Type") lvRow = 0 FOR index = lbound ( nameArray ) to ubound ( nameArray ) sob (soblv, "add" , "row", nameArray (index)) lvRow = lvRow + 1 sob (soblv, "set" , "cell", lvRow, 2, tkarr ( typeArray (index) -1 )) NEXT index END if SOB ( soblv, "SET" , "COLUMN" , "WIDTH" , -2 ) ' set colums widths to show all text ELSEIF ( useMethod == "EnumKey" ) then dim nameArray = Outparams . snames IF instr ( istype(nameArray ), "arr") then sob (soblv, "add" , "column", "Name") lvRow = 0 FOR index = lbound ( nameArray ) to ubound ( nameArray ) sob (soblv, "add" , "row", nameArray (index)) lvRow = lvRow + 1 NEXT index END if SOB ( soblv, "SET" , "COLUMN" , "WIDTH" , -2 ) ' set colums widths to show all text ELSEIF ( useMethod == "GetStringValue" ) then message = Outparams.sValue END if END Function ' ---------------------------------------------------------------------------------------------------------------- ' Useful definitions ' ---------------------------------------------------------------------------------------------------------------- Constant strComputer = "." ' means this computer ' ---------------------------------------------------------- ' hives Constant HKCR = 0xffffffff80000000 ' = HKEY_CLASSES_ROOT = -2147483648 in a 64 bit signed int Constant HKCU = 0xffffffff80000001 ' = HKEY_CURRENT_USER = -2147483647 Constant HKLM = 0xffffffff80000002 ' = HKEY_LOCAL_MACHINE = -2147483646 Constant HKU = 0xffffffff80000003 ' = HKEY_USERS = -2147483645 Constant HKCC = 0xffffffff80000005 ' = HKEY_CURRENT_CONFIG = -2147483643 ' ---------------------------------------------------------- ' Data Types Constant REG_NONE = 0 Constant REG_SZ = 1 Constant REG_EXPAND_SZ = 2 Constant REG_BINARY = 3 Constant REG_DWORD = 4 Constant REG_MULTI_SZ = 7 Constant REG_QWORD = 11 ' ---------------------------------------------------------- ' Access Rights - can be combined Constant KEY_QUERY_VALUE = 0x00000001 ' query the values of a registry key Constant KEY_SET_VALUE = 0x00000002 ' create, delete, or set a registry value Constant KEY_CREATE_SUB_KEY = 0x00000004 ' create a subkey of a registry key Constant KEY_ENUMERATE_SUB_KEYS = 0x00000008 ' enumerate the subkeys of a registry key Constant KEY_NOTIFY = 0x00000010 ' request change notifications for a registry key or for subkeys of a registry key. Constant KEY_CREATE = 0x00000020 ' create a registry key Constant DELETE = 0x00010000 ' delete a registry key Constant READ_CONTROL = 0x00020000 ' STANDARD_RIGHTS_READ, KEY_QUERY_VALUE, KEY_ENUMERATE_SUB_KEYS, and KEY_NOTIFY values. Constant WRITE_DAC = 0x00040000 ' modify the DACL in the object's security descriptor. Constant WRITE_OWNER = 0x00080000 ' neede to change the owner in the object's security descriptor. ' ---------------------------------------------------------- ' to find out more about StdRegProv ' https://docs.microsoft.com/en-us/previous-versions/windows/desktop/regprov/stdregprov ' or look at my script ' NS-Display-StdRegProv-Interface ' ---------------------------------------------------------------------------------------------------------------- ' Now start the work: ' ---------------------------------------------------------------------------------------------------------------- ' basically we use the OBJECT Wbemscripting.SWbemLocator dim objLocator = CreateObject("Wbemscripting.SWbemLocator") ' ---------------------------------------------------------- ' In some cases a method will require a specially prepared data structure ' this is handled using WbemScripting.SWbemNamedValueSet dim objCtx = CreateObject("WbemScripting.SWbemNamedValueSet") objCtx.Add ( "__ProviderArchitecture", 64 ) ' 32 or 64 bit ' ---------------------------------------------------------- dim objServices = objLocator.ConnectServer(strComputer,"root\default","","",,,,objCtx) dim objStdRegProv = objServices.Get("StdRegProv") ' ---------------------------------------------------------- ' now we need to create the REGISTRY access parameters ' do this in the Inparams ' Hdefkey ' identifies the HIVE ' sSubKeyName ' svaluename ' not all request need this, in fact not all request SUPPORT this parameter ' ---------------------------------------------------------- dim useMethod IF ( SelectExample = 1 ) then useMethod ="GetStringValue" dim Inparams = objStdRegProv.Methods_.item( useMethod ).Inparameters inparams.properties_.item("Hdefkey").Value = HKLM inparams.properties_.item("sSubKeyName").Value = "Software\Microsoft\Wbem\Scripting" inparams.properties_.item("Svaluename").Value = "Default Namespace" ELSEIF ( SelectExample = 2 ) then useMethod = "EnumValues" dim Inparams = objStdRegProv.Methods_.item( useMethod ).Inparameters inparams.properties_.item("Hdefkey").Value = HKCU inparams.properties_.item("sSubKeyName").Value = "Software\Microsoft\Office\12.0\Common\General\\" ELSEIF ( SelectExample = 3 ) then useMethod = "EnumKey" dim Inparams = objStdRegProv.Methods_.item( useMethod ).Inparameters inparams.properties_.item("Hdefkey").Value = HKCU inparams.properties_.item("sSubKeyName").Value = "Software\Microsoft\Office\12.0\Common\General\Signatures\\" ' ELSEIF ( SelectExample = 4 ) then ELSE message ="No example selected" stop END IF ' ---------------------------------------------------------- ' submit the request dim Outparams = objStdRegProv.ExecMethod_(useMethod ,Inparams,,objCtx) ' ---------------------------------------------------------- DisplayTrigger ( inparams , useMethod ) DisplayResponse ( outParams , useMethod ) nop ' script finished