Search the Community
Showing results for tags 'Registry'.
-
I'm writing a little applet that basically tells you when Windows was installed. There is a REG_DWORD in Windows that gives you this. It's basically a value that is the # of seconds from 1970. The location is: "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\InstallDate" So if I run this in AutoIT, I should get the value displayed within the msgbox: MsgBox($MB_SYSTEMMODAL, "InstallDate Test", RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "InstallDate")) However, what happens is it always returns a value of "0" I tried this on several machines (Windows 8, Windows 8.1 and Windows 10). Am I missing something? If I manually view this REG_DWORD with RegEdit, it shows me the HEX value, or I can view the Decimal value. I don't care which value AutoIT reads, as I can always convert back and forth, but I just don't see why it can't read a value from this REG_DWORD. As a test, I've read other REG_DWORD values, and with most it doesn't return any value, not even a 0. Please, even if you guys have some other (perhaps better) way to read the Windows install date, I would still like to find a resolution to this problem, because I want to understand why I am having so much difficulty with reading REG_DWORD values from the Windows Registry with AutoIT. Thanks for any help!
-
Maybe is not this big life issue, but I want to change the Windows 10/11 current user account picture with a script. Not so simple but doable, I took ideas from: https://social.msdn.microsoft.com/Forums/sqlserver/en-US/3f50b25a-4c47-4bc8-959e-1108419288a7/how-to-set-specific-users-account-picture-from-cmd?forum=scripting So I assembled a testbed scritpt to prepare the avatar images in various sizes, and to modify the registry, finding the right user SID and right keys to modify. All seems to work, even regwrite instruction results OK (1), but no changes in the registry. So I found a showstopper problem: this registry key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AccountPicture\Users contains the definitions of the images for the various users (take a look at attached screenshoot). But I am not able to modify that key or subkeys and neither modify permissions also with an admin, because it seems only the good old "Administrator" (disabled by default in modern OSes) is able to change that permissions. I say this because I reactivated manually the Administrator, but in some environments (corporate domains) it is not so simple. Ideas ? I hate to automate the windows gui for a task like this 😒.
-
Hi This piece of code creates and reads OK a key at "HKEY_LOCAL_MACHINE" and can be changed for a key at "HKEY_CURRENT_USER" $sta= RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor", "wav", "REG_SZ", "5555") MsgBox(4096,"wrote", $sta &@cr& @error) $zz= RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor", "wav") MsgBox(4096,"readed","="&$zz &@cr& @error) Exit With HKEY_CURRENT_USER, in RegEdit we can see the created key, and we can create the key by hand/RegEdit and everything Works OK. At HKEY_LOCAL_MACHINE we can´t see the created key above thru RegEdit, but it Works (even not seeing, I can read). But if I create "by hand"/RegEdit the key, it can´t read it with $zz= RegRead ("HKEY_LOCAL_MACHINE.... above. I´m the PC´s WIN.7 administrator. Even so I ran RegEdit as administrator and also the compiled AU3 and also plain. No changes. edit: even if Try "HKEY_LOCAL_MACHINE\SOFTWARE\AAA", "wav", the same holds true. $sta= RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\AAA", "wav", "REG_SZ", "4444") MsgBox(4096,"wrote", $sta &@cr& @error) $zz= RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\AAA", "wav") MsgBox(4096,"readed","="&$zz &@cr& @error) Exit Seems that it creates this key at another place.... I can read the above value ("4444"), even after a boot, even the key not showing in regedit. And if I create it by hand key AAA/wav with a distinct value (666), t, it continues Reading the old value = 444. Thanks Jose
-
good morning everybody. today i liked to share an small example with you which it an function to read the registry values as an array the result array is 2d array witch $a_array[n][0] = value name $a_array[n][1] = value Data $a_array[0][0] = values count here's the function #include <Array.au3> #include <WinAPIReg.au3> #include <APIRegConstants.au3> Local $a_array = _RegReadToArray("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run") If @error Then MsgBox(16, "error", @error) Exit EndIf _ArrayDisplay($a_array) Func _RegReadToArray($s_RegKey) Local $a_KeySplitInfo = StringSplit($s_RegKey, "\\", 2) If UBound($a_KeySplitInfo) <= 1 Then $a_KeySplitInfo = StringSplit($s_RegKey, "\", 2) If UBound($a_KeySplitInfo) <= 1 Then Return (1, 1, 0) EndIf Local $H_KeyInfo = "", $s_RegKeyInfo = "" Switch $a_KeySplitInfo[0] Case "hklm", "HKEY_LOCAL_MACHINE", "hklm64", "HKEY_LOCAL_MACHINE64" $H_KeyInfo = $HKEY_LOCAL_MACHINE Case "hkCu", "HKEY_CURRENT_USER", "hkCU64", "HKEY_CURRENT_USER64" $H_KeyInfo = $HKEY_CURRENT_USER Case "hkCr", "HKEY_CLASSES_ROOT", "HKCR64", "HKEY_CLASSES_ROOT64" $H_KeyInfo = $HKEY_CLASSES_ROOT Case "HKU", "HKEY_USERS", "HKU64", "HKEY_USERS64" $H_KeyInfo = $HKEY_USERS Case Else Return SetError(2, 2, 0) EndSwitch _ArrayDelete($a_KeySplitInfo, 0) $s_RegKeyInfo = _ArrayToString($a_KeySplitInfo, "\") Local $H_KeyInfoOpen = _WinAPI_RegOpenKey($H_KeyInfo, $s_RegKeyInfo, $KEY_READ) Local $A_KeyInfo = _WinAPI_RegQueryInfoKey($H_KeyInfoOpen) If @error Then Return SetError(1, 1, 0) _WinAPI_RegCloseKey($H_KeyInfoOpen) Local $A_RegVal[$A_KeyInfo[2] + 1][2] Local $iV = 1, $s_RegRead = "" While 1 $s_RegVal = RegEnumVal($s_RegKey, $iV) If @error <> 0 Then ExitLoop $s_RegRead = RegRead($s_RegKey, $s_RegVal) If Not (@error) Then $A_RegVal[$iV][0] = $s_RegVal $A_RegVal[$iV][1] = $s_RegRead EndIf $iV += 1 WEnd $A_RegVal[0][0] = UBound($A_RegVal) - 1 If $A_RegVal[0][0] >= 1 Then Return $A_RegVal Else Return SetError(3, 3, 0) EndIf EndFunc ;==>_RegReadToArray i hope you benefit from it with my greetings
-
I've looked at a bunch of SetACL examples on this site and none seem to be able to convert this batch script into a working AutoIt script. BATCH @echo off "%~dp0setacl.exe" -on "HKEY_CLASSES_ROOT\CLSID\{9C60DE1E-E5FC-40f4-A487-460851A8D915}\DefaultIcon" -ot reg -actn setowner -ownr n:administrators >nul 2>nul "%~dp0setacl.exe" -on "HKEY_CLASSES_ROOT\CLSID\{9C60DE1E-E5FC-40f4-A487-460851A8D915}\DefaultIcon" -ot reg -actn ace -ace "n:administrators;p:full" >nul 2>nul Reg.exe add "HKCR\CLSID\{9C60DE1E-E5FC-40f4-A487-460851A8D915}\DefaultIcon" /ve /t REG_EXPAND_SZ /d "C:\My.ico" /f NON-WORKING AUTOIT RunWait('setacl.exe "HKCR64\CLSID\{9C60DE1E-E5FC-40f4-A487-460851A8D915}\DefaultIcon" -ot reg -actn setowner -ownr "n:administrators"') RunWait('setacl.exe "HKCR64\CLSID\{9C60DE1E-E5FC-40f4-A487-460851A8D915}\DefaultIcon" -ot reg -actn setowner -ownr "n:administrators;p:full"') RegWrite('HKCR64\CLSID\{9C60DE1E-E5FC-40f4-A487-460851A8D915}\DefaultIcon', '','REG_EXPAND_SZ','C:\Windows\My.ico') Any ideas on what I'm doing wrong?
-
Need Help in adding hex values to registry
cahsobo posted a topic in AutoIt General Help and Support
Hello, I need help inserting these keys and values to registry [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\DirectDraw\Compatibility\WK.1.exe] "Flags"=hex:00,08,00,00 "ID"=hex:ec,33,74,3b Still can't figure out how... -
Hy to all, I am really Sorry to come up with this question but i can't seem to solve the Problem. Its quite easy, I have been using RegNumKey for Years, but i seemed to lose track of something. For $ZaehlerLocal = 1 to 1200 $RegKey = RegEnumKey("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall", $ZaehlerLocal) If @error <> 0 then ExitLoop $RegKey2=RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\"&$RegKey,"DisplayName") $RegKey3=RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\"&$RegKey,"UninstallString") $RegKey4=RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\"&$RegKey,"QuietUninstallString") if StringInStr($RegKey,"_Office15")==0 and StringInStr($RegKey2,"(German) 2013")==0 and StringInStr($RegKey,".KB")==0 and StringInStr($RegKey2,"Security update")==0 and StringInStr($RegKey2,"Framework")==0 Then FileWrite($FileHandleLocal,$RegKey&";") FileWrite($FileHandleLocal,$RegKey2&";") FileWrite($FileHandleLocal,$RegKey3&";") FileWriteline($FileHandleLocal,$RegKey4&";") EndIf Next Ive been using this to get all uninstall Strings from the Registry but for some reason, this doesn't work anymore. I get some keys but not all, nore does it start with the first registry. As you can see in the picture, the Registry starts with {13DA9C7C-EBFB-40D0-94A1-55B42883DF21} but RegNumKey starts with Adressbook. Any Ideas what I am doing wrong? I tried HKLM64 instead as well, but with same result. Again sorry to bother, but i can't Find the mistake.
-
Another project idea that I am trying to get working. A USB GPS device needs to be assigned COMM Port 25 when it is plugged into the computer. It obviously gets the first open port when plugged in the first time and if I manually change it to 25 it will get a new port again if somebody plugs the device into a new USB port. So I want to make a script that can detect the device, and move/configure its port automatically. I started off finding this UDF: https://www.autoitscript.com/forum/topic/128546-serial-port-com-port-udf/?page=32 It was useful for finding the device is plugged in and what port its on, but it does not have the ability to actually change the port. I think that will have to be done via registry, or perhaps via Objects. I just want to double check my facts here and get a grip on what I need to do. Registry has the following keys that change: HKLM\HARDWARE\SERIALCOMM - \Device\ProlificSerial0 This key just lists the COMM Port for the device, it changes based on its current port. HKLM\SYSTEM\CurrentControlSet\Enum\USB\VID_067B&PID_2303] Under this key is a subkey that will duplicate every time the device gets a new port, I have not figure out quite yet how to determin what that subkey will be named, but it has the "FriendlyName" key and also the Device parameters\PortName key Both of those are unfortunately SYSTEM level permission so that makes scripting a change even harder. Last is HKLM\SYSTEM\CurrentControlSet\Control\COM Name Arbiter This contains the record of what comm ports are occupied or vacant via binary to hex. I would have to find a way to read its current value and change it to show port 25 taken and if possible free up the port taken by the device before the change. Not sure how to write something like that. Has anybody done something like this before? If so what was your best approach?
-
Hi, I wondered why negative integers I wrote into registry (e.g. negative x-coordinates of a gui if using two monitors and the right one is the main one) wouldn't return right when reading. Now I know: it is saved as an unsigned integer (without algebraic sign). So here is a snippet that is changing unsigned to signed integer: Global Const $g_sRegKey = "HKEY_CURRENT_USER\Software\" & @ScriptName ; path to registry RegWrite($g_sRegKey, "Value", "REG_DWORD", -2147483647) ; write some negative integer into registry; -2147483647 highest possible negative integer , 2147483648 highest possible positive integer if talking of 32bit Local $sValue = RegRead($g_sRegKey, "Value") ; read out registry ConsoleWrite("Value: " & $sValue & @CRLF) ; show real value in console Local $sResult = _SignedInteger($sValue) ; change to signed value ConsoleWrite("Result: " & $sResult & @CRLF) ; and show it in console Func _SignedInteger($iUnsignedInteger) Local $iSignedInteger If $iUnsignedInteger > (2^31) Then ; then it means a negative integer $iSignedInteger = $iUnsignedInteger - (2^32) Else $iSignedInteger = $iUnsignedInteger EndIf Return $iSignedInteger EndFunc It took me some time to find out the problem and so I hope I can help somebody with this. Regards, Conrad
-
I needed a tool that would allow me to edit local group policy files. Registry policy files contain registry information used by the local group policy. Editing these files, followed by a `gpupdate /force` command allows you to enforce the modified local group policy. To my surprise, there aren't many editors out there for this type of file. I found a few implementations across the net, but none of them did everything I wanted or they were not free. Mainly I wanted a tool that provided read/write capabilities for the registry policy file format (.pol) via GUI and command line interface. So I created 'GPO Registry Editor' to solve this problem and I thought I would share it with the community. The script provides read/write access .pol file through GUI and CLI. I created the editor to be compliant with the Registry Policy File Format. However, in my testing the special values **DeleteKeys and **SecureKey do not conform the the format specification (at least not on Windows XP). Although I did implement these features, they do not perform the expected results when updated via gpupdate. The CLI has the following usage: GPO Registry Editor v1.0.0.0 Provides read and write capabilities for registry policy files. Usage: -a --add Add the entry specified by the key, value, type, and data parameters. -r --remove Remove the entry specified by the key and value parameters. -d --data Specifies the data of the registry entry. -f --file Specifies the registry file to load or modify. Use `computer` or `user` to specify the system policy files. -k --key Specifies the key of the registry entry. -s --silent Perform the operation silently (no GUI). -t --type Specifies the type of the registry entry. -v --value Specifies the value of the registry entry. -h --help Display this message. -? --? Display this message. Example: Add a value to the system Computer/Machine registry file. gre --add -f=computer -k=Software\Policies\Microsoft\MyTestKey -v="My Test Value" -t REG_SZ -d="Registry Policy File editing" Example: Remove a value from the system User registry file and suppress GUI error messages. gre --remove -f user -k Software\Policies\Microsoft\MyTestKey -v "My Test Value" -s Example: Delete all values of a key from a local file. gre --add -f=C:\Registry.pol -k=Software\Policies\Microsoft\MyTestKey -v=**DelValsSource code: #NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Compile_Both=y #AutoIt3Wrapper_UseX64=y #AutoIt3Wrapper_Res_Description=Provides read and write capabilities for registry policy files. #AutoIt3Wrapper_Res_Fileversion=1.0.0.0 #AutoIt3Wrapper_Res_Language=1033 #AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #cs ---------------------------------------------------------------------------- Title: GPO Registry Editor AutoIt Version: 3.3.8.1 Author: Michael Mims (zorphnog) Script Function: Provides read/write capabilities for the registry policy file format (.pol) via GUI or command line interface. Registry policy files contain registry information used by the local group policy. Editing these files, followed by a `gpupdate /force` command will update the local group policy. **Note: On Windows Vista and above, administrator rights are required to save to the system group policy folder. Compile with the requestedExecutionLevel=requireAdministrator directive to ensure administrator access. Reference(s): Registry Policy File Format - http://msdn.microsoft.com/en-us/library/windows/desktop/aa374407(v=vs.85).aspx #ce ---------------------------------------------------------------------------- #include <EditConstants.au3> #include <File.au3> #include <GuiComboBox.au3> #include <GuiConstants.au3> #include <GuiListView.au3> #include <Misc.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include "_OptParse.au3" ; Set Options Opt("GUICloseOnESC", 0) Opt("GUIOnEventMode", 1) Opt("MustDeclareVars", 1) ; Create mutex If @AutoItX64 And @Compiled Then _Singleton("GPO64_RE") Else _Singleton("GPO_RE") EndIf ; Application globals Global Const $GRE_TITLE = "GPO Registry Editor" Global Const $GRE_VERSION = "1.0.0.0" Global Const $GRE_DESC = "Provides read and write capabilities for registry policy files." ; File globals Global Const $GRE_LOG_FILE = @ScriptDir & "gre.log" Global Const $USER_REGISTRY_FILE = @SystemDir & "GroupPolicyUserRegistry.pol" Global Const $MACHINE_REGISTRY_FILE = @SystemDir & "GroupPolicyMachineRegistry.pol" ; Policy file format globals Global Const $REGISTRY_FILE_SIGNATURE = 0x67655250 Global Const $REGISTRY_FILE_VERSION = 0x00000001 Global Const $REGISTRY_FILE_ENCODING = 2 ; 1 - ANSI, 2 - UTF16 LE, 3 - UTF16 BE, 4 - UTF8 ; $g_aEntries array indices Global Enum $POLENTRY_KEY, $POLENTRY_VALUE, $POLENTRY_TYPE, $POLENTRY_SIZE, $POLENTRY_DATA ; Registry globals Global Enum $REG_NONE,$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 Global Const $g_REGTYPES[12] = [ "REG_NONE", "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"] Global Const $g_ENTRYREGTYPE_CONV[4] = [$REG_SZ,$REG_EXPAND_SZ,$REG_BINARY,$REG_DWORD] Global Const $g_ENTRYREGTYPES[4] = [$g_REGTYPES[$g_ENTRYREGTYPE_CONV[0]],$g_REGTYPES[$g_ENTRYREGTYPE_CONV[1]], _ $g_REGTYPES[$g_ENTRYREGTYPE_CONV[2]], $g_REGTYPES[$g_ENTRYREGTYPE_CONV[3]]] ; Policy entry type globals Global Enum $ENTRY_TYPE_NORM,$ENTRY_TYPE_DEL,$ENTRY_TYPE_DELMULVALS,$ENTRY_TYPE_DELALLVALS,$ENTRY_TYPE_DELKEYS, _ $ENTRY_TYPE_SECKEY,$_ENTRY_TYPE_SIZE Global Const $g_ENTRYTYPES[$_ENTRY_TYPE_SIZE] = ["Normal Entry", "Delete Value", "Delete Multiple Values", _ "Delete All Values", "Delete Subkeys", "Secure Key"] ; $g_MainCtrl array indices Global Enum $ENT_GUI,$ENT_CBENTR,$ENT_LBKEY,$ENT_INKEY,$ENT_LBVALU,$ENT_INVALU,$ENT_LBTYPE,$ENT_CBTYPE,$ENT_LBDATA, _ $ENT_INDATA,$ENT_LBDESC,$ENT_ILASTENTR,$_ENT_SIZE ; $g_EntryCtrl array indices Global Enum $MAIN_GUI,$MAIN_LVENTR,$MAIN_BTNEW,$MAIN_BTEDIT,$MAIN_BTDEL,$MAIN_MIMPOL,$MAIN_MIUPOL,$MAIN_MISAVE, _ $MAIN_MISAVA,$_MAIN_SIZE ; Command line option array indices Global Enum $GRE_OPT_ACTION,$GRE_OPT_FILE,$GRE_OPT_KEY,$GRE_OPT_VALUE,$GRE_OPT_TYPE,$GRE_OPT_DATA,$_GRE_OPT_SIZE Global Enum $GRE_ACTION_ADD,$GRE_ACTION_REMOVE ; Error code globals Global Enum Step *2 $GRE_ERROR_NONE=0,$GRE_ERROR_NOFILE=1,$GRE_ERROR_NOACTION,$GRE_ERROR_NOKEY,$GRE_ERROR_NOVALUE, _ $GRE_ERROR_NOTYPE,$GRE_ERROR_INVALIDTYPE,$GRE_ERROR_NODATA,$GRE_ERROR_FILENOTEXIST,$GRE_ERROR_INVALIDARG, _ $GRE_ERROR_DUPLICATEARG,$GRE_ERROR_INVALIDSWITCH,$GRE_ERROR_FILEWRITE,$GRE_ERROR_INVALIDREGISTRYSIG, _ $GRE_ERROR_INVALIDREGISTRYVERSION,$GRE_ERROR_ENTRYNOTFOUND,$GRE_ERROR_DELETEENTRY,$GRE_ERROR_INVALIDSPECVAL Global $g_aEntries[1][5], $g_MainCtrl[$_MAIN_SIZE], $g_EntryCtrl[$_ENT_SIZE] Global $g_sRegFile, $g_iEditLVIndex = -1, $g_bOpen = False, $g_bChanged = False, $g_bDebug = False, $g_bSilent = False _Main() Func _AddEntry($sKey, $sValue, $iType = 1, $vData = "") Local $iIndex = _FindEntry($sKey, $sValue) If @error Then $iIndex = UBound($g_aEntries) ReDim $g_aEntries[$iIndex + 1][5] $g_aEntries[$iIndex][$POLENTRY_KEY] = $sKey & ChrW(0) $g_aEntries[$iIndex][$POLENTRY_VALUE] = $sValue & ChrW(0) EndIf ; Force type for special values If StringLeft($sValue, 2) == "**" Then __DebugPrint("Special value; forcing REG_SZ", "_AddEntry") $iType = $REG_SZ EndIf $g_aEntries[$iIndex][$POLENTRY_TYPE] = Binary(Int($iType)) ; Determine if value is string data and convert properly Switch $iType Case $REG_SZ, $REG_EXPAND_SZ ; Check for special values If StringLeft($sValue, 2) == "**" Then Select Case StringMid($sValue, 3, 12) = "DeleteValues" Or StringMid($sValue, 3, 10) = "DeleteKeys" $vData = StringToBinary(StringRegExpReplace(StringStripWS($vData, 3), "(s*;s*)", ";") & _ ChrW(0), $REGISTRY_FILE_ENCODING) Case Else $vData = StringToBinary(ChrW(0x20) & ChrW(0), $REGISTRY_FILE_ENCODING) EndSelect Else $vData = StringToBinary($vData & ChrW(0), $REGISTRY_FILE_ENCODING) EndIf Case $REG_DWORD $vData = Binary(Int($vData)) Case Else $vData = Binary($vData) EndSwitch $g_aEntries[$iIndex][$POLENTRY_SIZE] = BinaryLen($vData) $g_aEntries[$iIndex][$POLENTRY_DATA] = $vData Return $iIndex EndFunc ;==>_AddEntry Func _CloseFile() If Not $g_bOpen Then Return True If $g_bOpen And $g_bChanged Then Local $iRet = MsgBox(0x1033, $GRE_TITLE, "The current registry file has been modified. Would you like to save the changes?", 0, $g_MainCtrl[$MAIN_GUI]) If $iRet = 2 Then ; CANCEL Return False ElseIf $iRet = 6 Then ; YES _SaveFile() EndIf EndIf _GUICtrlListView_DeleteAllItems($g_MainCtrl[$MAIN_LVENTR]) _ModifyFile(False, False) $g_aEntries = 0 Dim $g_aEntries[1][5] $g_sRegFile = "" Return True EndFunc ;==>_CloseFile Func _CreateEntryGUI($bIsNew = True) Local $sTitle = "Add" If Not $bIsNew Then $sTitle = "Edit" $g_EntryCtrl[$ENT_GUI] = GUICreate($sTitle & " Registry Entry", 520, 240, -1, -1, BitOR($WS_POPUP, $WS_CAPTION), $WS_EX_TOOLWINDOW, $g_MainCtrl[$MAIN_GUI]) GUICtrlCreateGroup("", 10, 10, 500, 185) $g_EntryCtrl[$ENT_CBENTR] = GUICtrlCreateCombo("", 20, 6, 135, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL)) GUICtrlSetData(-1, _ArrayToString($g_ENTRYTYPES), $g_ENTRYTYPES[0]) GUICtrlSetOnEvent(-1, "_Ev_cbEntryType") $g_EntryCtrl[$ENT_ILASTENTR] = 0 $g_EntryCtrl[$ENT_LBKEY] = GUICtrlCreateLabel("Key:", 20, 44, 45, 17, $SS_RIGHT) $g_EntryCtrl[$ENT_INKEY] = GUICtrlCreateInput("", 70, 41, 430, 21) $g_EntryCtrl[$ENT_LBVALU] = GUICtrlCreateLabel("Value:", 20, 76, 45, 17, $SS_RIGHT) $g_EntryCtrl[$ENT_INVALU] = GUICtrlCreateInput("", 70, 73, 430, 21) $g_EntryCtrl[$ENT_LBTYPE] = GUICtrlCreateLabel("Type:", 20, 108, 45, 17, $SS_RIGHT) $g_EntryCtrl[$ENT_CBTYPE] = GUICtrlCreateCombo("", 70, 105, 240, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL)) GUICtrlSetData(-1, _ArrayToString($g_ENTRYREGTYPES), $g_ENTRYREGTYPES[0]) $g_EntryCtrl[$ENT_LBDATA] = GUICtrlCreateLabel("Data:", 20, 140, 45, 17, $SS_RIGHT) $g_EntryCtrl[$ENT_INDATA] = GUICtrlCreateInput("", 70, 137, 430, 42, $ES_MULTILINE) $g_EntryCtrl[$ENT_LBDESC] = GUICtrlCreateLabel("", 70, 100, 430, 68) GUICtrlSetFont(-1, Default, Default, 2) GUICtrlSetState(-1, $GUI_HIDE) GUICtrlCreateGroup("", -99, -99, 1, 1) GUICtrlCreateButton("OK", 350, 205, 75, 25) GUICtrlSetOnEvent(-1, "_Ev_btEntryOk") GUICtrlCreateButton("Cancel", 435, 205, 75, 25) GUICtrlSetOnEvent(-1, "_Ev_btEntryCancel") EndFunc ;==>_CreateEntryGUI Func _CreateGUI() $g_MainCtrl[$MAIN_GUI] = GUICreate($GRE_TITLE, 770, 475, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_MAXIMIZEBOX, $WS_SIZEBOX)) GUISetOnEvent($GUI_EVENT_CLOSE, "_Ev_miFileClose") GUICtrlCreateListView("Registry Key|Value|Type|Data", 10, 10, 750, 400) $g_MainCtrl[$MAIN_LVENTR] = GUICtrlGetHandle(-1) GUICtrlSendMsg(-1, 0x101E, 0, 350) GUICtrlSendMsg(-1, 0x101E, 1, 150) GUICtrlSendMsg(-1, 0x101E, 2, 100) GUICtrlSendMsg(-1, 0x101E, 3, 100) GUICtrlSetResizing(-1, $GUI_DOCKBORDERS) $g_MainCtrl[$MAIN_BTNEW] = GUICtrlCreateButton("New...", 10, 420, 75, 25, 0) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlSetOnEvent(-1, "_Ev_btNew") GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT,$GUI_DOCKBOTTOM,$GUI_DOCKSIZE)) $g_MainCtrl[$MAIN_BTEDIT] = GUICtrlCreateButton("Edit...", 95, 420, 75, 25, 0) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlSetOnEvent(-1, "_Ev_btEdit") GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT,$GUI_DOCKBOTTOM,$GUI_DOCKSIZE)) $g_MainCtrl[$MAIN_BTDEL] = GUICtrlCreateButton("Delete", 180, 420, 75, 25, 0) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlSetOnEvent(-1, "_Ev_btDelete") GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT,$GUI_DOCKBOTTOM,$GUI_DOCKSIZE)) ; Menu items Local $muFile, $muOpen $muFile = GUICtrlCreateMenu("File") GUICtrlCreateMenuItem("New", $muFile) GUICtrlSetOnEvent(-1, "_Ev_miFileNew") $muOpen = GUICtrlCreateMenu("Open", $muFile) $g_MainCtrl[$MAIN_MIMPOL] = GUICtrlCreateMenuItem("Machine Policy", $muOpen) GUICtrlSetOnEvent(-1, "_Ev_miFileOpenSystem") $g_MainCtrl[$MAIN_MIUPOL] = GUICtrlCreateMenuItem("User Policy", $muOpen) GUICtrlSetOnEvent(-1, "_Ev_miFileOpenSystem") GUICtrlCreateMenuItem("", $muOpen) GUICtrlCreateMenuItem("File...", $muOpen) GUICtrlSetOnEvent(-1, "_Ev_miFileOpenFile") $g_MainCtrl[$MAIN_MISAVE] = GUICtrlCreateMenuItem("Save", $muFile) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlSetOnEvent(-1, "_Ev_miFileSave") $g_MainCtrl[$MAIN_MISAVA] = GUICtrlCreateMenuItem("Save As...", $muFile) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlSetOnEvent(-1, "_Ev_miFileSave") GUICtrlCreateMenuItem("", $muFile) GUICtrlCreateMenuItem("Exit", $muFile) GUICtrlSetOnEvent(-1, "_Ev_miFileClose") GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") GUISetState(@SW_SHOW) EndFunc ;==>_CreateGUI Func _DeleteEntry($sKey, $sValue) Local $iIndex = _FindEntry($sKey, $sValue) If @error Then Return SetError(@error, 0, -1) __DebugPrint("--key=" & $sKey & " --value=" & $sValue, "_DeleteEntry") _ArrayDelete($g_aEntries, $iIndex) If @error Then Return SetError($GRE_ERROR_DELETEENTRY, 0, -1) Return 1 EndFunc ;==>_DeleteEntry Func _EditEntry($iEntry = -1) If $iEntry == -1 Then $g_iEditLVIndex = $iEntry _CreateEntryGUI() Else _CreateEntryGUI(False) _LoadEntryValues($iEntry) EndIf GUISetState(@SW_DISABLE, $g_MainCtrl[$MAIN_GUI]) GUISetState(@SW_SHOW, $g_EntryCtrl[$ENT_GUI]) EndFunc ;==>_EditEntry Func _FindEntry($sKey, $sValue) Local $iCurrent, $iIndex, $iSize $iCurrent = 0 $iSize = UBound($g_aEntries) While $iCurrent < $iSize $iIndex = _ArraySearch($g_aEntries, $sValue, $iCurrent, 0, 0, 0, 1, $POLENTRY_VALUE) If @error Then ExitLoop If $g_aEntries[$iIndex][$POLENTRY_KEY] = $sKey Then __DebugPrint($iIndex & " " & $g_aEntries[$iIndex][$POLENTRY_KEY], "_FindEntry") Return $iIndex EndIf $iCurrent = $iIndex + 1 WEnd Return SetError($GRE_ERROR_ENTRYNOTFOUND, 0, -1) EndFunc ;==>_FindEntry Func _GetFormattedData($iIndex, $bHex = True) Switch $g_aEntries[$iIndex][$POLENTRY_TYPE] Case $REG_SZ, $REG_EXPAND_SZ Return BinaryToString($g_aEntries[$iIndex][$POLENTRY_DATA], $REGISTRY_FILE_ENCODING) Case $REG_BINARY Return "0x" & Hex(Int($g_aEntries[$iIndex][$POLENTRY_DATA]), 8) Case $REG_DWORD If $bHex Then Return "0x" & Hex(Int($g_aEntries[$iIndex][$POLENTRY_DATA]), 8) Return Int($g_aEntries[$iIndex][$POLENTRY_DATA]) Case Else Return $g_aEntries[$iIndex][4] EndSwitch EndFunc ;==>_GetFormattedData Func _LoadEntryValues($iEntry) Local $iEntryType, $sKey, $sValue, $iRegType, $sValue $iEntryType = 0 $sKey = $g_aEntries[$iEntry][$POLENTRY_KEY] $sValue = $g_aEntries[$iEntry][$POLENTRY_VALUE] If StringLeft($sValue, 2) == "**" Then Select Case StringMid($sValue, 3, 12) = "DeleteValues" $iEntryType = $ENTRY_TYPE_DELMULVALS $sValue = BinaryToString($g_aEntries[$iEntry][$POLENTRY_DATA], $REGISTRY_FILE_ENCODING) $iRegType = 0 Case StringMid($sValue, 3, 4) = "Del." $iEntryType = $ENTRY_TYPE_DEL $sValue = StringMid($sValue, 7) $iRegType = 0 Case StringMid($sValue, 3, 7) = "DelVals" $iEntryType = $ENTRY_TYPE_DELALLVALS $sValue = "" $iRegType = 0 Case StringMid($sValue, 3, 10) = "DeleteKeys" $iEntryType = $ENTRY_TYPE_DELKEYS $sValue = BinaryToString($g_aEntries[$iEntry][$POLENTRY_DATA], $REGISTRY_FILE_ENCODING) $iRegType = 0 Case StringMid($sValue, 3, 9) = "SecureKey" $iEntryType = $ENTRY_TYPE_SECKEY $iRegType = Int(StringMid($sValue, 13, 1)) $sValue = "" EndSelect _GUICtrlComboBox_SetCurSel($g_EntryCtrl[$ENT_CBENTR], $iEntryType) _Ev_cbEntryType() GUICtrlSetData($g_EntryCtrl[$ENT_INKEY], $sKey) GUICtrlSetData($g_EntryCtrl[$ENT_INVALU], $sValue) _GUICtrlComboBox_SetCurSel($g_EntryCtrl[$ENT_CBTYPE], $iRegType) Else $iRegType = _ArraySearch($g_ENTRYREGTYPE_CONV, $g_aEntries[$iEntry][$POLENTRY_TYPE]) GUICtrlSetData($g_EntryCtrl[$ENT_INKEY], $sKey) GUICtrlSetData($g_EntryCtrl[$ENT_INVALU], $sValue) _GUICtrlComboBox_SetCurSel($g_EntryCtrl[$ENT_CBTYPE], $iRegType) GUICtrlSetData($g_EntryCtrl[$ENT_INDATA], _GetFormattedData($iEntry, False)) EndIf EndFunc ;==>_LoadEntryValues Func _Main() Local $aValidOpts, $aOptions, $sFilename = "" If @CPUArch = "X64" And Not @AutoItX64 Then ;~ __DebugPrint("X64 architecture detected.", "_Main", True) Local $sDrive, $sDir, $sFile, $sExt, $sExec _PathSplit(@ScriptFullPath, $sDrive, $sDir, $sFile, $sExt) $sExec = @ScriptDir & "" & $sFile & "_x64" & $sExt ;~ __DebugPrint("Attempting 64 bit launch: " & $sExec, "_Main", True) If FileExists($sExec) Then Exit(RunWait($sExec & " " & _ArrayToString($CmdLine, " ", 1), @WorkingDir)) EndIf If _ParseOptions($aValidOpts, $aOptions) Then Local $iOption, $iMatches = 0 If _OptParse_MatchOption("h,help,?", $aOptions, $iOption) Then _OptParse_ShowUsage($aValidOpts, 1) Exit($GRE_ERROR_NONE) EndIf If _OptParse_MatchOption("D,debug", $aOptions, $iOption) Then $iMatches += 1 $g_bDebug = True __PrintEnvironment() EndIf If _OptParse_MatchOption("s,silent", $aOptions, $iOption) Then __DebugPrint("Silent mode set", "_Main") $iMatches += 1 $g_bSilent = True _OptParse_SetDisplay(0) EndIf If _OptParse_MatchOption("f,file", $aOptions, $iOption) Then $iMatches += 1 Switch StringLower($aOptions[$iOption][1]) Case "c","comp","computer","m","machine" $sFilename = $MACHINE_REGISTRY_FILE Case "u","user" $sFilename = $USER_REGISTRY_FILE Case Else $sFilename = _PathFull($aOptions[$iOption][1]) EndSwitch __DebugPrint("[file] " & $sFilename, "_Main") EndIf ; Some command line parameters for testing ; --add -f Registry.pol -k SoftwareMyTestKey -v TestMe -t REG_SZ -d "test, test, test" ; --remove -f Registry.pol -k SoftwareMyTestKey -v TestMe If _OptParse_MatchOption("a,add,r,remove", $aOptions, $iOption) Then Local $iReturn, $aValidated = _ValidateOptions($aOptions) _ReadPolFile($sFilename) If @error Then Exit(@error) If $aValidated[$GRE_OPT_ACTION] == $GRE_ACTION_ADD Then _AddEntry($aValidated[$GRE_OPT_KEY], $aValidated[$GRE_OPT_VALUE], $aValidated[$GRE_OPT_TYPE], _ $aValidated[$GRE_OPT_DATA]) ElseIf $aValidated[$GRE_OPT_ACTION] == $GRE_ACTION_REMOVE Then _DeleteEntry($aValidated[$GRE_OPT_KEY], $aValidated[$GRE_OPT_VALUE]) If @error Then Exit(@error) EndIf _WritePolFile($sFilename) If @error Then Exit(@error) Exit($GRE_ERROR_NONE) ElseIf $iMatches < $aOptions[0][0] Then _OptParse_Display("No action specified. Use --add or --remove to modify a policy file.", "Error") Exit($GRE_ERROR_NOACTION) EndIf EndIf _CreateGUI() If $sFilename <> "" Then _OpenFile($sFilename) While 1 Sleep(10) WEnd EndFunc ;==>_Main Func _ModifyFile($bNewOpen, $bNewChanged) Local $sTitle, $aClientSize, $a_iCall __DebugPrint(StringFormat("[%s, %s] => [%s, %s]", $g_bOpen, $g_bChanged, $bNewOpen, $bNewChanged), "_ModifyFile") If $bNewOpen <> $g_bOpen Then If $bNewOpen Then If $g_sRegFile == "" Then $sTitle = "New Policy File - " & $GRE_TITLE Else $sTitle = $g_sRegFile & " - " & $GRE_TITLE EndIf $aClientSize = WinGetClientSize($g_MainCtrl[$MAIN_GUI]) $a_iCall = DllCall("shlwapi.dll", "int", "PathCompactPathW", _ "hwnd", 0, _ "wstr", $sTitle, _ "dword", $aClientSize[0] - 100) If Not @error Then $sTitle = $a_iCall[2] WinSetTitle($g_MainCtrl[$MAIN_GUI], 0, $sTitle) GUICtrlSetState($g_MainCtrl[$MAIN_MISAVA], $GUI_ENABLE) GUICtrlSetState($g_MainCtrl[$MAIN_BTNEW], $GUI_ENABLE) GUICtrlSetState($g_MainCtrl[$MAIN_BTEDIT], $GUI_ENABLE) GUICtrlSetState($g_MainCtrl[$MAIN_BTDEL], $GUI_ENABLE) Else WinSetTitle($g_MainCtrl[$MAIN_GUI], 0, $GRE_TITLE) GUICtrlSetState($g_MainCtrl[$MAIN_MISAVE], $GUI_DISABLE) GUICtrlSetState($g_MainCtrl[$MAIN_MISAVA], $GUI_DISABLE) GUICtrlSetState($g_MainCtrl[$MAIN_BTNEW], $GUI_DISABLE) GUICtrlSetState($g_MainCtrl[$MAIN_BTEDIT], $GUI_DISABLE) GUICtrlSetState($g_MainCtrl[$MAIN_BTDEL], $GUI_DISABLE) $g_bChanged = False EndIf $g_bOpen = $bNewOpen Return EndIf If $bNewChanged <> $g_bChanged And $g_bOpen Then If $bNewChanged Then If $g_sRegFile == "" Then $sTitle = "New Policy File* - " & $GRE_TITLE Else $sTitle = $g_sRegFile & "* - " & $GRE_TITLE EndIf $aClientSize = WinGetClientSize($g_MainCtrl[$MAIN_GUI]) $a_iCall = DllCall("shlwapi.dll", "int", "PathCompactPathW", _ "hwnd", 0, _ "wstr", $sTitle, _ "dword", $aClientSize[0] - 100) If Not @error Then $sTitle = $a_iCall[2] WinSetTitle($g_MainCtrl[$MAIN_GUI], 0, $sTitle) GUICtrlSetState($g_MainCtrl[$MAIN_MISAVE], $GUI_ENABLE) Else If $g_sRegFile == "" Then $sTitle = "New Policy File - " & $GRE_TITLE Else $sTitle = $g_sRegFile & " - " & $GRE_TITLE EndIf $aClientSize = WinGetClientSize($g_MainCtrl[$MAIN_GUI]) $a_iCall = DllCall("shlwapi.dll", "int", "PathCompactPathW", _ "hwnd", 0, _ "wstr", $sTitle, _ "dword", $aClientSize[0] - 100) If Not @error Then $sTitle = $a_iCall[2] WinSetTitle($g_MainCtrl[$MAIN_GUI], 0, $sTitle) GUICtrlSetState($g_MainCtrl[$MAIN_MISAVE], $GUI_DISABLE) EndIf EndIf $g_bChanged = $bNewChanged EndFunc ;==>_ModifyFile Func _OpenFile($sFilename = "") If Not _CloseFile() Then Return If $sFilename <> "" Then GUISetCursor(15, 1, $g_MainCtrl[$MAIN_GUI]) _ReadPolFile($sFilename) If @error Then GUISetCursor() Return EndIf _UpdateListView() GUISetCursor() EndIf $g_sRegFile = $sFilename _ModifyFile(True, False) EndFunc ;==>_OpenFile Func _ParseOptions(ByRef $aValidOpts, ByRef $aOptions) Local $local_CmdLine = $CmdLine $aValidOpts = 0 $aOptions = 0 ; Create the valid options list _OptParse_Init($aValidOpts, $GRE_TITLE & "n", "v" & $GRE_VERSION & "n", $GRE_DESC & "n") _OptParse_Add($aValidOpts, "a", "add", $OPT_ARG_NONE, "Add the entry specified by the key, value, type, and data parameters.") _OptParse_Add($aValidOpts, "r", "remove", $OPT_ARG_NONE, "Remove the entry specified by the key and value parameters.") _OptParse_Add($aValidOpts, "D", "debug", BitOR($OPT_ARG_NONE,$OPT_ARG_HIDDEN), "Record debugging information.") _OptParse_Add($aValidOpts, "d", "data", $OPT_ARG_REQ, "Specifies the data of the registry entry.") _OptParse_Add($aValidOpts, "f", "file", $OPT_ARG_REQ, "Specifies the registry file to load or modify. Use `computer` or `user` to specify the system policy files.") _OptParse_Add($aValidOpts, "k", "key", $OPT_ARG_REQ, "Specifies the key of the registry entry.") _OptParse_Add($aValidOpts, "s", "silent", $OPT_ARG_NONE, "Perform the operation silently (no GUI).") _OptParse_Add($aValidOpts, "t", "type", $OPT_ARG_REQ, "Specifies the type of the registry entry.") _OptParse_Add($aValidOpts, "v", "value", $OPT_ARG_REQ, "Specifies the value of the registry entry.") _OptParse_Add($aValidOpts, "h", "help", $OPT_ARG_NONE, "Display this message.") _OptParse_Add($aValidOpts, "?", "?", $OPT_ARG_NONE, "Display this message.") $aOptions = _OptParse_GetOpts($local_CmdLine, $aValidOpts) Switch @error Case 0 _OptParse_SetDisplay(1) ; Display via MsgBox Return True Case 1 _OptParse_SetDisplay(1) ; Display via MsgBox Return False Case 2 Exit($GRE_ERROR_INVALIDARG) Case 3 Exit($GRE_ERROR_DUPLICATEARG) Case 4 Exit($GRE_ERROR_INVALIDSWITCH) EndSwitch EndFunc ;==>_ParseOptions Func _ReadPolFile($sFilename) Local $hInfile, $bBuffer, $iStart, $iCurrent, $iLength, $iColon, $iNumEntries, $bTemp If Not FileExists($sFilename) Then If Not $g_bSilent Then MsgBox(0x1010, $GRE_TITLE, "ERROR: File not found: " & $sFilename) Return SetError($GRE_ERROR_FILENOTEXIST, 0, -1) EndIf $hInfile = FileOpen($sFilename, 16) $bBuffer = FileRead($hInfile) FileClose($hInfile) $iLength = BinaryLen($bBuffer) If BinaryMid($bBuffer, 1, 4) <> Binary($REGISTRY_FILE_SIGNATURE) Then If Not $g_bSilent Then MsgBox(0x1010, $GRE_TITLE, "ERROR: Invalid file signature. File will not be processed.") Return SetError($GRE_ERROR_INVALIDREGISTRYSIG, 0, -1) EndIf If BinaryMid($bBuffer, 5, 4) <> Binary($REGISTRY_FILE_VERSION) Then If Not $g_bSilent Then MsgBox(0x1010, $GRE_TITLE, "ERROR: Invalid registry file version. File will not be processed.") Return SetError($GRE_ERROR_INVALIDREGISTRYVERSION, 0, -1) EndIf $iStart = 9 $iCurrent = 9 $iColon = 0 $iNumEntries = 0 $g_aEntries = 0 Dim $g_aEntries[1][5] ; The body consists of registry values in the following format. ; [key;value;type;size;data] While $iCurrent < $iLength $bTemp = BinaryMid($bBuffer, $iCurrent, 2) Switch $bTemp Case 0x005B ; Unicode => [ ReDim $g_aEntries[$iNumEntries+1][5] $iColon = 0 $iStart = $iCurrent + 2 Case 0x005D ; Unicode => ] $iStart = $iCurrent + 2 $iNumEntries += 1 Case 0x003B ; Unicode => ; Switch $iColon Case 0 $g_aEntries[$iNumEntries][$POLENTRY_KEY] = BinaryToString(BinaryMid($bBuffer, $iStart, $iCurrent - $iStart), $REGISTRY_FILE_ENCODING) $iColon += 1 $iStart = $iCurrent + 2 Case 1 $g_aEntries[$iNumEntries][$POLENTRY_VALUE] = BinaryToString(BinaryMid($bBuffer, $iStart, $iCurrent - $iStart), $REGISTRY_FILE_ENCODING) $iColon += 1 $iStart = $iCurrent + 2 Case 2 ;~ _ArrayDisplay($g_aEntries) $g_aEntries[$iNumEntries][$POLENTRY_TYPE] = Int(BinaryMid($bBuffer, $iStart, $iCurrent - $iStart)) $iColon += 1 $iStart = $iCurrent + 2 Case 3 $g_aEntries[$iNumEntries][$POLENTRY_SIZE] = Int(BinaryMid($bBuffer, $iStart, $iCurrent - $iStart)) $iColon += 1 $iStart = $iCurrent + 2 $g_aEntries[$iNumEntries][$POLENTRY_DATA] = BinaryMid($bBuffer, $iStart, $g_aEntries[$iNumEntries][$POLENTRY_SIZE]) $iCurrent = $iStart + $g_aEntries[$iNumEntries][$POLENTRY_SIZE] - 2 Case Else $iColon += 1 $iStart = $iCurrent + 2 EndSwitch EndSwitch $iCurrent += 2 WEnd EndFunc ;==>_ReadPolFile Func _SaveFile($bSaveAs = False) If $bSaveAs Or Not FileExists($g_sRegFile) Then Local $sFilename = FileSaveDialog("Save GPO Registry File...", "", "GPO Registry Files (*.pol)", 18, "", $g_MainCtrl[$MAIN_GUI]) If @error Then Return False If StringRight($sFilename, 4) <> ".pol" Then $sFilename &= ".pol" $g_sRegFile = $sFilename EndIf _WritePolFile($g_sRegFile) If @error Then Return False _ModifyFile($g_bOpen, False) EndFunc ;==>_SaveFile Func _UpdateListView() Local $i, $iMax _GUICtrlListView_BeginUpdate($g_MainCtrl[$MAIN_LVENTR]) _GUICtrlListView_DeleteAllItems($g_MainCtrl[$MAIN_LVENTR]) $iMax = UBound($g_aEntries) - 1 For $i=0 To $iMax _GUICtrlListView_AddItem($g_MainCtrl[$MAIN_LVENTR], $g_aEntries[$i][$POLENTRY_KEY]) _GUICtrlListView_AddSubItem($g_MainCtrl[$MAIN_LVENTR], $i, $g_aEntries[$i][$POLENTRY_VALUE], 1) _GUICtrlListView_AddSubItem($g_MainCtrl[$MAIN_LVENTR], $i, $g_REGTYPES[$g_aEntries[$i][$POLENTRY_TYPE]], 2) _GUICtrlListView_AddSubItem($g_MainCtrl[$MAIN_LVENTR], $i, _GetFormattedData($i), 3) Next _GUICtrlListView_EndUpdate($g_MainCtrl[$MAIN_LVENTR]) EndFunc ;==>_UpdateListView Func _ValidateOptions($aOptions) Local $aReturn[$_GRE_OPT_SIZE], $iOption ; Check for policy file definition If Not _OptParse_MatchOption("f,file", $aOptions, $iOption) Then _OptParse_Display("File required. Use --file to specify the policy file to modify.", "Error") Exit($GRE_ERROR_NOFILE) EndIf ; Check for key definition If _OptParse_MatchOption("k,key", $aOptions, $iOption) Then __DebugPrint("[key] " & $aOptions[$iOption][1], "_ValidateOptions") $aReturn[$GRE_OPT_KEY] = $aOptions[$iOption][1] Else _OptParse_Display("Key required. Use --key to specify the registry key to modify.", "Error") Exit($GRE_ERROR_NOKEY) EndIf ; Check for value definition If _OptParse_MatchOption("v,value", $aOptions, $iOption) Then __DebugPrint("[value] " & $aOptions[$iOption][1], "_ValidateOptions") $aReturn[$GRE_OPT_VALUE] = $aOptions[$iOption][1] Else _OptParse_Display("Value required. Use --value to specify the registry value to modify.", "Error") Exit($GRE_ERROR_NOVALUE) EndIf If _OptParse_MatchOption("r,remove", $aOptions, $iOption) Then __DebugPrint("[action] remove", "_ValidateOptions") $aReturn[$GRE_OPT_ACTION] = $GRE_ACTION_REMOVE Return $aReturn ElseIf _OptParse_MatchOption("a,add", $aOptions, $iOption) Then Local $sType, $sData, $bTypeRequired = True, $bDataRequired = True __DebugPrint("[action] add", "_ValidateOptions") $aReturn[$GRE_OPT_ACTION] = $GRE_ACTION_ADD ; Handle special values and determine whether data is required If StringLeft($aReturn[$GRE_OPT_VALUE], "2") == "**" Then Select Case StringMid($aReturn[$GRE_OPT_VALUE], 3, 4) = "Del." Or _ StringMid($aReturn[$GRE_OPT_VALUE], 3, 7) = "DelVals" Or _ StringMid($aReturn[$GRE_OPT_VALUE], 3, 9) = "SecureKey" __DebugPrint("Special value detected; data not required.", "_ValidateOptions") $bTypeRequired = False $bDataRequired = False Case StringMid($aReturn[$GRE_OPT_VALUE], 3, 12) = "DeleteValues" Or _ StringMid($aReturn[$GRE_OPT_VALUE], 3, 10) = "DeleteKeys" __DebugPrint("Special value detected; data required.", "_ValidateOptions") $bTypeRequired = False Case Else _OptParse_Display("Invalid special value: " & $aReturn[$GRE_OPT_VALUE], "Error") Exit($GRE_ERROR_INVALIDSPECVAL) EndSelect EndIf ; Check for type definition If _OptParse_MatchOption("t,type", $aOptions, $iOption) Then __DebugPrint("[type] " & $aOptions[$iOption][1], "_ValidateOptions") $aReturn[$GRE_OPT_TYPE] = StringUpper($aOptions[$iOption][1]) $aReturn[$GRE_OPT_TYPE] = _ArraySearch($g_REGTYPES, $aReturn[$GRE_OPT_TYPE]) If @error Then _OptParse_Display("Invalid type argument: " & $aOptions[$iOption][1], "Error") Exit($GRE_ERROR_INVALIDTYPE) EndIf ElseIf $bTypeRequired Then _OptParse_Display("Type required. Use --type to specify the registry type to add.", "Error") Exit($GRE_ERROR_NOTYPE) EndIf ; Check for data definition If _OptParse_MatchOption("d,data", $aOptions, $iOption) Then __DebugPrint("[data] " & $aOptions[$iOption][1], "_ValidateOptions") $aReturn[$GRE_OPT_DATA] = $aOptions[$iOption][1] ElseIf $bDataRequired Then _OptParse_Display("Data required. Use --data to specify the registry data to add.", "Error") Exit($GRE_ERROR_NODATA) EndIf Return $aReturn EndIf EndFunc ;==>_ValidateOptions Func _WritePolFile($sFilename) Local $hOutfile, $iMax ; Open file for writing __DebugPrint("Writing output file...", "_WritePolFile") $hOutfile = FileOpen($sFilename, 26) If $hOutfile = -1 Then If Not $g_bSilent Then MsgBox(0x1010, $GRE_TITLE, "ERROR: File could not be created [" & $sFilename & "].") Return SetError($GRE_ERROR_FILEWRITE, 0, -1) EndIf ; Write header information FileWrite($hOutfile, Binary($REGISTRY_FILE_SIGNATURE)) FileWrite($hOutfile, Binary($REGISTRY_FILE_VERSION)) ; Write entries $iMax = UBound($g_aEntries) - 1 For $i = 0 To $iMax FileWrite($hOutfile, StringToBinary("[" & $g_aEntries[$i][$POLENTRY_KEY], $REGISTRY_FILE_ENCODING)) FileWrite($hOutfile, StringToBinary(";", $REGISTRY_FILE_ENCODING)) FileWrite($hOutfile, StringToBinary($g_aEntries[$i][$POLENTRY_VALUE], $REGISTRY_FILE_ENCODING)) FileWrite($hOutfile, StringToBinary(";", $REGISTRY_FILE_ENCODING)) FileWrite($hOutfile, $g_aEntries[$i][$POLENTRY_TYPE]) FileWrite($hOutfile, StringToBinary(";", $REGISTRY_FILE_ENCODING)) FileWrite($hOutfile, $g_aEntries[$i][$POLENTRY_SIZE]) FileWrite($hOutfile, StringToBinary(";", $REGISTRY_FILE_ENCODING)) FileWrite($hOutfile, $g_aEntries[$i][$POLENTRY_DATA]) FileWrite($hOutfile, StringToBinary("]", $REGISTRY_FILE_ENCODING)) Next ; Close file FileClose($hOutfile) EndFunc ;==>_WritePolFile Func _Ev_btDelete() Local $iIndex = _GUICtrlListView_GetSelectedIndices($g_MainCtrl[$MAIN_LVENTR]) If $iIndex <> "" Then _DeleteEntry(_GUICtrlListView_GetItemText($g_MainCtrl[$MAIN_LVENTR], $iIndex), _GUICtrlListView_GetItemText($g_MainCtrl[$MAIN_LVENTR], $iIndex, 1)) If Not @error Then _GUICtrlListView_DeleteItem($g_MainCtrl[$MAIN_LVENTR], $iIndex) _ModifyFile($g_bOpen, True) EndIf EndIf EndFunc ;==>_Ev_btDelete Func _Ev_btEdit() Local $iEntry, $iIndex = _GUICtrlListView_GetSelectedIndices($g_MainCtrl[$MAIN_LVENTR]) If $iIndex <> "" Then $iEntry = _FindEntry(_GUICtrlListView_GetItemText($g_MainCtrl[$MAIN_LVENTR], $iIndex), _GUICtrlListView_GetItemText($g_MainCtrl[$MAIN_LVENTR], $iIndex, 1)) If Not @error Then $g_iEditLVIndex = $iIndex _EditEntry($iEntry) EndIf EndIf EndFunc ;==>_Ev_btEdit Func _Ev_btEntryCancel() GUISetState(@SW_ENABLE, $g_MainCtrl[$MAIN_GUI]) GUIDelete($g_EntryCtrl[$ENT_GUI]) EndFunc ;==>_Ev_btEntryCancel Func _Ev_btEntryOk() Local $iIndex, $iEntry, $sKey, $sValue, $iType, $vData $sKey = GUICtrlRead($g_EntryCtrl[$ENT_INKEY]) $sValue = GUICtrlRead($g_EntryCtrl[$ENT_INVALU]) $iType = $g_ENTRYREGTYPE_CONV[_GUICtrlComboBox_GetCurSel($g_EntryCtrl[$ENT_CBTYPE])] $vData = GUICtrlRead($g_EntryCtrl[$ENT_INDATA]) Switch _GUICtrlComboBox_GetCurSel($g_EntryCtrl[$ENT_CBENTR]) Case $ENTRY_TYPE_DEL $sValue = "**Del." & $sValue $iType = $REG_SZ Case $ENTRY_TYPE_DELMULVALS $vData = $sValue $sValue = "**DeleteValues" $iType = $REG_SZ Case $ENTRY_TYPE_DELALLVALS $sValue = "**DelVals." $iType = $REG_SZ Case $ENTRY_TYPE_DELKEYS $vData = $sValue $sValue = "**DeleteKeys" & ChrW(0) $iType = $REG_SZ Case $ENTRY_TYPE_SECKEY $sValue = "**SecureKey=" & _GUICtrlComboBox_GetCurSel($g_EntryCtrl[$ENT_CBTYPE]) $iType = $REG_SZ EndSwitch $iEntry = _AddEntry($sKey, $sValue, $iType, $vData) If $g_iEditLVIndex == -1 Then $iIndex = _GUICtrlListView_AddItem($g_MainCtrl[$MAIN_LVENTR], $g_aEntries[$iEntry][$POLENTRY_KEY]) If $iIndex <> -1 Then _GUICtrlListView_AddSubItem($g_MainCtrl[$MAIN_LVENTR], $iIndex, $g_aEntries[$iEntry][$POLENTRY_VALUE], 1) _GUICtrlListView_AddSubItem($g_MainCtrl[$MAIN_LVENTR], $iIndex, $g_REGTYPES[$g_aEntries[$iEntry][$POLENTRY_TYPE]], 2) _GUICtrlListView_AddSubItem($g_MainCtrl[$MAIN_LVENTR], $iIndex, _GetFormattedData($iEntry), 3) EndIf Else Local $sLVKey, $sLVValue $sLVKey = _GUICtrlListView_GetItemText($g_MainCtrl[$MAIN_LVENTR], $g_iEditLVIndex) $sLVValue = _GUICtrlListView_GetItemText($g_MainCtrl[$MAIN_LVENTR], $g_iEditLVIndex, 1) ; Update list view entry _GUICtrlListView_SetItemText($g_MainCtrl[$MAIN_LVENTR], $g_iEditLVIndex, $g_aEntries[$iEntry][$POLENTRY_KEY]) _GUICtrlListView_SetItemText($g_MainCtrl[$MAIN_LVENTR], $g_iEditLVIndex, $g_aEntries[$iEntry][$POLENTRY_VALUE], 1) _GUICtrlListView_SetItemText($g_MainCtrl[$MAIN_LVENTR], $g_iEditLVIndex, $g_REGTYPES[$g_aEntries[$iEntry][$POLENTRY_TYPE]], 2) _GUICtrlListView_SetItemText($g_MainCtrl[$MAIN_LVENTR], $g_iEditLVIndex, _GetFormattedData($iEntry), 3) ; Delete old entry if necessary If $sLVKey <> $sKey Or $sLVValue <> $sValue Then _DeleteEntry($sLVKey, $sLVValue) EndIf _ModifyFile($g_bOpen, True) GUISetState(@SW_ENABLE, $g_MainCtrl[$MAIN_GUI]) GUIDelete($g_EntryCtrl[$ENT_GUI]) EndFunc ;==>_Ev_btEntryOk Func _Ev_btNew() _EditEntry() EndFunc ;==>_Ev_btNew Func _Ev_cbEntryType() Local $iSelected = _GUICtrlComboBox_GetCurSel($g_EntryCtrl[$ENT_CBENTR]) If $iSelected = $g_EntryCtrl[$ENT_ILASTENTR] Then Return Switch $iSelected Case $ENTRY_TYPE_NORM GUICtrlSetState($g_EntryCtrl[$ENT_LBDESC], $GUI_HIDE) GUICtrlSetData($g_EntryCtrl[$ENT_LBVALU], "Value:") GUICtrlSetState($g_EntryCtrl[$ENT_LBVALU], $GUI_SHOW) GUICtrlSetState($g_EntryCtrl[$ENT_INVALU], $GUI_SHOW) GUICtrlSetPos($g_EntryCtrl[$ENT_LBTYPE], 20, 108) GUICtrlSetData($g_EntryCtrl[$ENT_LBTYPE], "Type:") GUICtrlSetState($g_EntryCtrl[$ENT_LBTYPE], $GUI_SHOW) GUICtrlSetPos($g_EntryCtrl[$ENT_CBTYPE], 70, 105, 240) _GUICtrlComboBox_ResetContent($g_EntryCtrl[$ENT_CBTYPE]) GUICtrlSetData($g_EntryCtrl[$ENT_CBTYPE], _ArrayToString($g_ENTRYREGTYPES), $g_ENTRYREGTYPES[0]) GUICtrlSetState($g_EntryCtrl[$ENT_CBTYPE], $GUI_SHOW) GUICtrlSetState($g_EntryCtrl[$ENT_LBDATA], $GUI_SHOW) GUICtrlSetState($g_EntryCtrl[$ENT_INDATA], $GUI_SHOW) Case $ENTRY_TYPE_DEL GUICtrlSetState($g_EntryCtrl[$ENT_LBTYPE], $GUI_HIDE) GUICtrlSetState($g_EntryCtrl[$ENT_CBTYPE], $GUI_HIDE) GUICtrlSetState($g_EntryCtrl[$ENT_LBDATA], $GUI_HIDE) GUICtrlSetState($g_EntryCtrl[$ENT_INDATA], $GUI_HIDE) GUICtrlSetData($g_EntryCtrl[$ENT_LBVALU], "Value:") GUICtrlSetState($g_EntryCtrl[$ENT_LBVALU], $GUI_SHOW) GUICtrlSetState($g_EntryCtrl[$ENT_INVALU], $GUI_SHOW) GUICtrlSetPos($g_EntryCtrl[$ENT_LBDESC], 70, 100) GUICtrlSetData($g_EntryCtrl[$ENT_LBDESC], "Deletes the value from the associated key.") GUICtrlSetState($g_EntryCtrl[$ENT_LBDESC], $GUI_SHOW) Case $ENTRY_TYPE_DELMULVALS GUICtrlSetState($g_EntryCtrl[$ENT_LBTYPE], $GUI_HIDE) GUICtrlSetState($g_EntryCtrl[$ENT_CBTYPE], $GUI_HIDE) GUICtrlSetState($g_EntryCtrl[$ENT_LBDATA], $GUI_HIDE) GUICtrlSetState($g_EntryCtrl[$ENT_INDATA], $GUI_HIDE) GUICtrlSetData($g_EntryCtrl[$ENT_LBVALU], "Values:") GUICtrlSetState($g_EntryCtrl[$ENT_LBVALU], $GUI_SHOW) GUICtrlSetState($g_EntryCtrl[$ENT_INVALU], $GUI_SHOW) GUICtrlSetPos($g_EntryCtrl[$ENT_LBDESC], 70, 100) GUICtrlSetData($g_EntryCtrl[$ENT_LBDESC], _ StringFormat("Deletes multiple values from the associated key. Specify multiple values using a " & _ "semicolon-delimited list.rnExample: type;size;NoRun;NoFind")) GUICtrlSetState($g_EntryCtrl[$ENT_LBDESC], $GUI_SHOW) Case $ENTRY_TYPE_DELALLVALS GUICtrlSetState($g_EntryCtrl[$ENT_LBVALU], $GUI_HIDE) GUICtrlSetState($g_EntryCtrl[$ENT_INVALU], $GUI_HIDE) GUICtrlSetState($g_EntryCtrl[$ENT_LBTYPE], $GUI_HIDE) GUICtrlSetState($g_EntryCtrl[$ENT_CBTYPE], $GUI_HIDE) GUICtrlSetState($g_EntryCtrl[$ENT_LBDATA], $GUI_HIDE) GUICtrlSetState($g_EntryCtrl[$ENT_INDATA], $GUI_HIDE) GUICtrlSetPos($g_EntryCtrl[$ENT_LBDESC], 70, 68) GUICtrlSetData($g_EntryCtrl[$ENT_LBDESC], "Deletes all values from the associated key.") GUICtrlSetState($g_EntryCtrl[$ENT_LBDESC], $GUI_SHOW) Case $ENTRY_TYPE_DELKEYS GUICtrlSetState($g_EntryCtrl[$ENT_LBTYPE], $GUI_HIDE) GUICtrlSetState($g_EntryCtrl[$ENT_CBTYPE], $GUI_HIDE) GUICtrlSetState($g_EntryCtrl[$ENT_LBDATA], $GUI_HIDE) GUICtrlSetState($g_EntryCtrl[$ENT_INDATA], $GUI_HIDE) GUICtrlSetData($g_EntryCtrl[$ENT_LBVALU], "Subkeys:") GUICtrlSetState($g_EntryCtrl[$ENT_LBVALU], $GUI_SHOW) GUICtrlSetState($g_EntryCtrl[$ENT_INVALU], $GUI_SHOW) GUICtrlSetPos($g_EntryCtrl[$ENT_LBDESC], 70, 100) GUICtrlSetData($g_EntryCtrl[$ENT_LBDESC], _ StringFormat("Deletes multiple subkeys from the associated key. Specify multiple subkeys using a " & _ "semicolon-delimited list.rnExample: type;size;NoRun;NoFind")) GUICtrlSetState($g_EntryCtrl[$ENT_LBDESC], $GUI_SHOW) Case $ENTRY_TYPE_SECKEY GUICtrlSetState($g_EntryCtrl[$ENT_LBVALU], $GUI_HIDE) GUICtrlSetState($g_EntryCtrl[$ENT_INVALU], $GUI_HIDE) GUICtrlSetState($g_EntryCtrl[$ENT_LBDATA], $GUI_HIDE) GUICtrlSetState($g_EntryCtrl[$ENT_INDATA], $GUI_HIDE) GUICtrlSetPos($g_EntryCtrl[$ENT_LBTYPE], 20, 76) GUICtrlSetData($g_EntryCtrl[$ENT_LBTYPE], "Secure:") GUICtrlSetState($g_EntryCtrl[$ENT_LBTYPE], $GUI_SHOW) GUICtrlSetPos($g_EntryCtrl[$ENT_CBTYPE], 70, 73, 50) _GUICtrlComboBox_ResetContent($g_EntryCtrl[$ENT_CBTYPE]) GUICtrlSetData($g_EntryCtrl[$ENT_CBTYPE], "False|True", "True") GUICtrlSetState($g_EntryCtrl[$ENT_CBTYPE], $GUI_SHOW) GUICtrlSetPos($g_EntryCtrl[$ENT_LBDESC], 70, 100) GUICtrlSetData($g_EntryCtrl[$ENT_LBDESC], _ "Secures the associated key, giving administrators and the system full control, and giving " & _ "users read-only access. If set to False, access to the key resets to whatever is set on the root.") GUICtrlSetState($g_EntryCtrl[$ENT_LBDESC], $GUI_SHOW) EndSwitch $g_EntryCtrl[$ENT_ILASTENTR] = $iSelected EndFunc ;==>_Ev_cbEntryType Func _Ev_miFileClose() If Not _CloseFile() Then Return Exit($GRE_ERROR_NONE) EndFunc ;==>_Ev_miFileClose Func _Ev_miFileNew() If Not _CloseFile() Then Return _OpenFile() EndFunc ;==>_Ev_miFileNew Func _Ev_miFileOpenFile() If Not _CloseFile() Then Return Local $sFilename = FileOpenDialog("Select GPO Registry File", "", "GPO Registry Files (*.pol)|All Files (*.*)", 3, "", $g_MainCtrl[$MAIN_GUI]) If @error Then Return _OpenFile($sFilename) EndFunc ;==>_Ev_miFileOpenFile Func _Ev_miFileOpenSystem() If Not _CloseFile() Then Return Switch @GUI_CtrlId Case $g_MainCtrl[$MAIN_MIMPOL] _OpenFile($MACHINE_REGISTRY_FILE) Case $g_MainCtrl[$MAIN_MIUPOL] _OpenFile($USER_REGISTRY_FILE) EndSwitch EndFunc ;==>_Ev_miFileOpenSystem Func _Ev_miFileSave() Switch @GUI_CtrlId Case $g_MainCtrl[$MAIN_MISAVE] _SaveFile() Case $g_MainCtrl[$MAIN_MISAVA] _SaveFile(True) EndSwitch EndFunc ;==>_Ev_miFileSave Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $tNMHDR, $hWndFrom, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom") $iCode = DllStructGetData($tNMHDR, "Code") If $hWndFrom = $g_MainCtrl[$MAIN_LVENTR] And $iCode == $NM_DBLCLK Then _Ev_btEdit() Return $GUI_RUNDEFMSG EndFunc ;==>_WM_NOTIFY Func __DebugPrint($sMessage, $sSource = "Info", $bOverride = False) If Not $g_bDebug And Not $bOverride Then Return Local $sLine = StringFormat("%02d%02d%04d %02d:%02d:%02d %-20s %srn", _ @MON, @MDAY, @YEAR, @HOUR, @MIN, @SEC, $sSource, $sMessage) If @Compiled Then FileWrite($GRE_LOG_FILE, $sLine) Else ConsoleWrite($sLine) EndIf EndFunc ;==>__DebugPrint Func __PrintEnvironment() Local $sEnv = @CRLF $sEnv &= StringFormat(" OSVersion: %srn", @OSVersion) $sEnv &= StringFormat(" OSArch: %srn", @OSArch) $sEnv &= StringFormat(" AutoItX64: %srn", @AutoItX64) $sEnv &= StringFormat(" WindowsDir: %srn", @WindowsDir) $sEnv &= StringFormat(" SystemDir: %srn", @SystemDir) $sEnv &= StringFormat(" TempDir: %srn", @TempDir) $sEnv &= StringFormat(" ComSpec: %srn", @ComSpec) $sEnv &= StringFormat(" ProgramFilesDir: %s", @ProgramFilesDir) __DebugPrint($sEnv, "__PrintEnvironment", True) EndFunc ;==>__PrintEnvironmentEnjoy and please let me know if there are any issues. GRE_source.zip **Note: On Windows Vista and above, administrator rights are required to save to the system group policy folder. Compile with the requestedExecutionLevel=requireAdministrator directive to ensure administrator access.
- 12 replies
-
- registry
- group policy
-
(and 1 more)
Tagged with:
-
Hi All, Sorry for my English I searched the forum a function like that, and not found, indeed, there are many topics request regarding all this function, and I have done this, I did not know what name to put them RegEnumKeyToArray or RegListToArray or ect ect in the end I chose _RegEnumKeyValEx (_RegEnumKeyEx & _RegEnumValEx), the function does almost everything (also includes $sFilter as the >_FileListToArrayEx), and works really fast too #include-once ; #UDF# ======================================================================================================================= ; Title .........: Reads\Search the name of a Key\Subkey\Value ; AutoIt Version : 3.3.8.1 ; Language ......: English ; Description ...: Lists all Keys\Subkeys\Values in a specified registry key ; Author(s) .....: DXRW4E ; Notes .........: ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ;~ _RegEnumKeyEx ;~ _RegEnumValEx ; =============================================================================================================================== #Region ;**** Global constants and vars **** Global Const $sValueTypes[12] = ["REG_NONE","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"] #EndRegion ;**** Global constants and vars **** ; #FUNCTION# ======================================================================================================================== ; Name...........: _RegEnumKeyEx ; Description ...: Lists all subkeys in a specified registry key ; Syntax.........: _RegEnumKeyEx($KeyName[, $iFlag = 0[, $sFilter = "*"]]) ; Parameters ....: $KeyName - The registry key to read. ; $iFlag - Optional specifies Recursion (add the flags together for multiple operations): ; |$iFlag = 0 (Default) All Key-SubKeys Recursive Mod ; |$iFlag = 1 All SubKeys Not Recursive Mod ; |$iFlag = 2 Include in ArrayList in the first element $KeyName ; |$iFlag = 16 $sFilter do Case-Sensitive matching (By Default $sFilter do Case-Insensitive matching) ; |$iFlag = 32 Disable the return the count in the first element - effectively makes the array 0-based (must use UBound() to get the size in this case). ; By Default the first element ($array[0]) contains the number of strings returned, the remaining elements ($array[1], $array[2], etc.) ; |$iFlag = 64 $sFilter is REGEXP Mod, See Pattern Parameters in StringRegExp ; |$iFlag = 128 Enum value's name (_RegEnumKeyEx Return a 2D array, maximum Array Size limit is 3999744 Key\Value) ; |$iFlag = 256 Reads a value data, this flag will be ignored if the $iFlag = 128 is not set ; $sFilter - Optional the filter to use, default is *. (Multiple filter groups such as "All "*.XXx|*.YYY|*.ZZZ") ; Search the Autoit3 helpfile for the word "WildCards" For details. ; $vFilter - Optional the filter to use for ValueName, $vFilter will be ignored if the $iFlag = 128 is not set ; default is *. (Multiple filter groups such as "All "*.XXx|*.YYY|*.ZZZ") Search the Autoit3 helpfile for the word "WildCards" For details. ; $iValueTypes - Optional, set Value Types to search (Default $iValueTypes = 0 Read All), $iValueTypes will be ignored if the $iFlag = 128 is not set ; (add the flags together for multiple operations): ; 1 = REG_SZ ; 2 = REG_EXPAND_SZ ; 3 = REG_BINARY ; 4 = REG_DWORD ; 5 = REG_DWORD_BIG_ENDIAN ; 6 = REG_LINK ; 7 = REG_MULTI_SZ ; 8 = REG_RESOURCE_LIST ; 9 = REG_FULL_RESOURCE_DESCRIPTOR ; 10 = REG_RESOURCE_REQUIREMENTS_LIST ; 11 = REG_QWORD ; Return values .: Success - Return Array List (See Remarks) ; Failure - @Error ; |1 = Invalid $sFilter ; |2 = No Key-SubKey(s) Found ; |3 = Invalid $vFilter ; |4 = No Value-Name(s) Found ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: The array returned is one-dimensional and is made up as follows: ; $array[0] = Number of Key-SubKeys returned ; $array[1] = 1st Key\SubKeys ; $array[2] = 2nd Key\SubKeys ; $array[3] = 3rd Key\SubKeys ; $array[n] = nth Key\SubKeys ; ; If is set the $iFlag = 128 The array returned is 2D array and is made up as follows: ; $array[0][0] = Number of Key-SubKeys returned ; $array[1][0] = 1st Key\SubKeys ; $array[1][1] = 1st Value name ; $array[1][2] = 1st Value Type (REG_NONE or REG_SZ or REG_EXPAND_SZ ect ect) ; $array[1][3] = 1st Value Data (If is set $iFlag = 256 Else Value Data = "") ; $array[2][0] = 2nd Key\SubKeys ; $array[2][1] = 2nd Value name ; $array[2][2] = 2nd Value Type (REG_NONE or REG_SZ or REG_EXPAND_SZ ect ect) ; $array[2][3] = 2nd Value Data (If is set $iFlag = 256 Else Value Data = "") ; $array[n][0] = nth Key\SubKeys ; Related .......: _RegEnumValEx() ; Link ..........: ; Example .......: _RegEnumKeyEx("HKEY_CURRENT_USER\Software\AutoIt v3") ; Note ..........: ; =================================================================================================================================== Func _RegEnumKeyEx($KeyName, $iFlag = 0, $sFilter = "*", $vFilter = "*", $iValueTypes = 0) If StringRegExp($sFilter, StringReplace("^\s*$|\v|\\|^\||\|\||\|$", Chr(BitAND($iFlag, 64) + 28) & "\|^\||\|\||\|$", "\\\\")) Then Return SetError(1, 0, "") Local $IndexSubKey[101] = [100], $SubKeyName, $BS = "\", $sKeyList, $I = 1, $sKeyFlag = BitAND($iFlag, 1), $sKeyFilter = StringReplace($sFilter, "*", "") If BitAND($iFlag, 2) Then $sKeyList = @LF & $KeyName If Not BitAND($iFlag, 64) Then $sFilter = StringRegExpReplace(BitAND($iFlag, 16) & "(?i)(", "16\(\?\i\)|\d+", "") & StringRegExpReplace(StringRegExpReplace(StringRegExpReplace(StringRegExpReplace($sFilter, "[^*?|]+", "\\Q$0\\E"), "\\E(?=\||$)", "$0\$"), "(?<=^|\|)\\Q", "^$0"), "\*+", ".*") & ")" While $I $IndexSubKey[$I] += 1 $SubKeyName = RegEnumKey($KeyName, $IndexSubKey[$I]) If @error Then $IndexSubKey[$I] = 0 $I -= 1 $KeyName = StringLeft($KeyName, StringInStr($KeyName, "\", 1, -1) - 1) ContinueLoop EndIf If $sKeyFilter Then If StringRegExp($SubKeyName, $sFilter) Then $sKeyList &= @LF & $KeyName & $BS & $SubKeyName Else $sKeyList &= @LF & $KeyName & $BS & $SubKeyName EndIf If $sKeyFlag Then ContinueLoop $I += 1 If $I > $IndexSubKey[0] Then $IndexSubKey[0] += 100 ReDim $IndexSubKey[$IndexSubKey[0] + 1] EndIf $KeyName &= $BS & $SubKeyName WEnd If Not $sKeyList Then Return SetError(2, 0, "") If BitAND($iFlag, 128) <> 128 Then Return StringSplit(StringTrimLeft($sKeyList, 1), @LF, StringReplace(BitAND($iFlag, 32), "32", 2)) $sKeyList = _RegEnumValEx(StringSplit(StringTrimLeft($sKeyList, 1), @LF), $iFlag, $vFilter, $iValueTypes) Return SetError(@Error, 0, $sKeyList) EndFunc ; #FUNCTION# ======================================================================================================================== ; Name...........: _RegEnumValEx ; Description ...: Lists all values in a specified registry key ; Syntax.........: _RegEnumValEx($KeyName[, $iFlag = 0[, $sFilter = "*"]]) ; Parameters ....: $KeyName - The registry key to read Or one-dimensional array RegKeyList ; use _RegEnumKeyEx() to get $RegKeyList (example $RegKeyList = [3, 1st Key\SubKeys, 2st Key\SubKeys, nth Key\SubKeys]) ; |$iFlag = 16 $sFilter do Case-Sensitive matching (By Default $sFilter do Case-Insensitive matching) ; |$iFlag = 32 Disable the return the count in the first element - effectively makes the array 0-based (must use UBound() to get the size in this case). ; By Default the first element ($array[0]) contains the number of strings returned, the remaining elements ($array[1], $array[2], etc.) ; |$iFlag = 64 $sFilter is REGEXP Mod, See Pattern Parameters in StringRegExp ; |$iFlag = 256 Reads a value data ; $sFilter - Optional the filter to use, default is *. (Multiple filter groups such as "All "*.XXx|*.YYY|*.ZZZ") ; Search the Autoit3 helpfile for the word "WildCards" For details. ; $iValueTypes - Optional, set Value Types to search (Default $iValueTypes = 0 Read All) ; (add the flags together for multiple operations): ; 1 = REG_SZ ; 2 = REG_EXPAND_SZ ; 3 = REG_BINARY ; 4 = REG_DWORD ; 5 = REG_DWORD_BIG_ENDIAN ; 6 = REG_LINK ; 7 = REG_MULTI_SZ ; 8 = REG_RESOURCE_LIST ; 9 = REG_FULL_RESOURCE_DESCRIPTOR ; 10 = REG_RESOURCE_REQUIREMENTS_LIST ; 11 = REG_QWORD ; Return values .: Success - Return Array List (See Remarks) ; Failure - @Error ; |3 = Invalid $sFilter ; |4 = No Value-Name(s) Found ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: The array returned is 2D array and is made up as follows: ; $array[0][0] = Number of Key-SubKeys returned ; $array[1][0] = 1st Key\SubKeys ; $array[1][1] = 1st Value name ; $array[1][2] = 1st Value Type (REG_NONE or REG_SZ or REG_EXPAND_SZ ect ect) ; $array[1][3] = 1st Value Data (If is set $iFlag = 256 Else Value Data = "") ; $array[2][0] = 2nd Key\SubKeys ; $array[2][1] = 2nd Value name ; $array[2][2] = 2nd Value Type (REG_NONE or REG_SZ or REG_EXPAND_SZ ect ect) ; $array[2][3] = 2nd Value Data (If is set $iFlag = 256 Else Value Data = "") ; $array[n][0] = nth Key\SubKeys ; Related .......: _RegEnumKeyEx() ; Link ..........: ; Example .......: _RegEnumValEx("HKEY_CURRENT_USER\Software\AutoIt v3") ; Note ..........: ; =================================================================================================================================== Func _RegEnumValEx($aKeyList, $iFlag = 0, $sFilter = "*", $iValueTypes = 0) If StringRegExp($sFilter, "\v") Then Return SetError(3, 0, "") If Not IsArray($aKeyList) Then $aKeyList = StringSplit($aKeyList, @LF) Local $aKeyValList[1954][4], $iKeyVal = Int(BitAND($iFlag, 32) = 0), $sKeyVal = 1953, $sRegEnumVal, $iRegEnumVal, $RegRead = BitAND($iFlag, 256), $vFilter = StringReplace($sFilter, "*", "") If Not BitAND($iFlag, 64) Then $sFilter = StringRegExpReplace(BitAND($iFlag, 16) & "(?i)(", "16\(\?\i\)|\d+", "") & StringRegExpReplace(StringRegExpReplace(StringRegExpReplace(StringRegExpReplace($sFilter, "[^*?|]+", "\\Q$0\\E"), "\\E(?=\||$)", "$0\$"), "(?<=^|\|)\\Q", "^$0"), "\*+", ".*") & ")" For $i = 1 To $aKeyList[0] $iRegEnumVal = 0 While 1 If $iKeyVal = $sKeyVal Then If $sKeyVal = 3999744 Then ExitLoop $sKeyVal *= 2 ReDim $aKeyValList[$sKeyVal + 1][4] EndIf $aKeyValList[$iKeyVal][0] = $aKeyList[$i] $iRegEnumVal += 1 $sRegEnumVal = RegEnumVal($aKeyList[$i], $iRegEnumVal) If @Error <> 0 Then If $iRegEnumVal = 1 And $vFilter = "" Then $iKeyVal += 1 ExitLoop EndIf $aKeyValList[$iKeyVal][2] = $sValueTypes[@Extended] If BitAND(@Extended, $iValueTypes) <> $iValueTypes Then ContinueLoop If $vFilter And Not StringRegExp($sRegEnumVal, $sFilter) Then ContinueLoop $aKeyValList[$iKeyVal][1] = $sRegEnumVal If $RegRead Then $aKeyValList[$iKeyVal][3] = RegRead($aKeyList[$i], $sRegEnumVal) $iKeyVal += 1 WEnd Next $sRegEnumVal = $iKeyVal - Int(BitAND($iFlag, 32) = 0) If Not $sRegEnumVal Or ($sRegEnumVal = 1 And $vFilter = "" And $aKeyValList[$iKeyVal - $sRegEnumVal][2] = "") Then Return SetError(4, 0, "") ReDim $aKeyValList[$iKeyVal][4] If Not BitAND($iFlag, 32) Then $aKeyValList[0][0] = $iKeyVal - 1 Return $aKeyValList EndFuncexample #RequireAdmin #include <_RegEnumKeyValEx.au3> #include <Array.au3> Global $a, $t, $Error, $Extended, $KeyName ;$KeyName = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft" ;$KeyName = "HKEY_CLASSES_ROOT" ;104718 ;$KeyName = "HKEY_LOCAL_MACHINE\SOFTWARE\Classes" $KeyName = "HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3" $t = TimerInit() ;$a = _RegEnumKeyEx($KeyName, 0, "Opti*Components") ; to find HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\OptionalComponents ;$a = _RegEnumKeyEx($KeyName, 0, "*") $a = _RegEnumKeyEx($KeyName, 128 + 256 + 32 + 16, "*", "*vers*") $Error = @Error $Extended = @Extended $t = TimerDiff($t) ConsoleWrite("Timer = " & $t & @LF) ConsoleWrite("Return = " & $a & " - $Error = " & $Error & " - $Extended = " & $Extended & @LF) _ArrayDisplay($a) ;or $a = _RegEnumKeyEx("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3", 128 + 256) ;Return 2D array all Keys\Subkes\Values ect ect _ArrayDisplay($a) $a = _RegEnumKeyEx("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3", 128 + 256, "*","*Ver*on*") ;Return $a[2][4] = [[1],["HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt","Version","REG_SZ","v3.3.8.1"]] _ArrayDisplay($a) $a = _RegEnumKeyEx("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3", 128 + 256 + 32, "*","*ver*on*") ;Return $a[1][4] = [["HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt","Version","REG_SZ","v3.3.8.1"]] _ArrayDisplay($a) $a = _RegEnumKeyEx("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3", 128 + 256 + 16, "*","*ver*on*") ;Return @Error = 4 ($iFlag = 16 $sFilter do Case-Sensitive matching, Version <> version) ;_ArrayDisplay($a) $a = _RegEnumValEx("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", 256,"*Ver*on*") ;Return $a[2][4] = [[1],["HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt","Version","REG_SZ","v3.3.8.1"]] _ArrayDisplay($a)_RegEnumKeyValEx.au3
- 15 replies
-
- _filelisttoarrayex
- regenumkeytoarray
- (and 7 more)
-
Hi! I post here because i was wonderring if someone in this forum could help me with my script. What i'm trying to do, is to basically install a new keyboard layout in Windows and activate it. I want to acheive by the registry or the command line, but not with the autoit automation tools, i don't find it stable... Thanks for your help and have a good day!
-
Hello guys, I'm having a problem right here .. I was trying to create a few Registry Values using autoit, but it seems to me that Autoit can't write those values to this specific part of the registry .. Here is the code I'm trying to run: RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\test\command", "", "REG_SZ", "C:\test\convert.exe %1 geojson|convert") I'm definitly sure that the path is correct. Script is runned with Admin Rights. Everything's fine here. It's possible to read other values stored by Windows in this directory: MsgBox(0, 0, RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Windows.burn", "Description")) But you can't edit those using Autoit. I don't know what this is. In my eyes it's an Autoit Bug or something like that ... Possible solution for me is to write a ".reg" file and run it afterwards, but this is an unclean method I don't really want to use .. Any suggestions on this? Edit: the OS is Windows 7 x64 German Language btw ..
-
I have a registry value in which the name is having \ and when I am trying to delete the registry,it is failing because of \. The registry is given below. Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Microsoft\Active Setup\Installed Components\{2D46B6DC-2207-486B-B523-A557E6D54B47}] "Version"="9,0,8112,16421" "Locale"="*" "C:\\ProgramData\\Symantec\\Symantec Endpoint Protection\\"="C:\\ProgramData\\Symantec\\Symantec Endpoint Protection\\" Can you please suggest how to delete the last value.
-
Making a backup of the entire Registry
Wicked_Caty posted a topic in AutoIt General Help and Support
I wanted to have a few lines that copy the whole registry into a file. I know that there is RegRead, but I don't want to type every single key into my code... Any way of doing this easily? Filetype doesn't matter, as long as it isn't encrypted. A batch or exe would be okay, if it's in the same location on every PC. Doing this without admin permissions would be awesome too Thanks -
I am trying to create anti-procrastination software, basically by utilizing the DisallowRun parameter in the Group Policy. I am adding registry values into the register to add the programs I want disallowed through the restricted.txt file (each line in the file is a program I want to disallow) So, this is what I have so far and it does work, but There was a time that it didn't, and the only reason is because of permissions. ;Anti-Procrastinator V0.1 ;Checks version of windows, if 32x or 64x Dim $registryKey If @OSType = "WIN32_NT" Then $registryKey = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" EndIf Dim $restrictionFile startup() Func startup() RegWrite($registryKey, "DisallowRun", "REG_DWORD", 1) $registryKey &= "\DisallowRun" addToReg() EndFunc ;Adds programs in Restricted.txt into the registry Func addToReg() $restrictionFile = FileOpen("Restricted.txt") Dim $str = FileReadLine($restrictionFile), $count = 1 While Not @error While $str <> "" RegWrite($registryKey, ""&$count, "REG_SZ", $str) $str = FileReadLine($restrictionFile) $count += 1 WEnd WEnd FileClose($restrictionFile) EndFunc ;...What I had to do, to get this working, is go into the registry and manually set the Explorer folders permissions to full access for my account. If I use #REQUIREADMIN it will work (assuming that access is given, but I don't want to ask for admin privileges, well, unless I can brute force a yes). I have also noticed in other posts, it doesn't mention you need to change permissions, something I had to piece together myself! So, what I want to know, is how to I get the permissions to be full control to me, without having to manually set them. Or be able to brute force admin rights (which I don't think is possible)
-
This is a script I put together to make it as fast and as easy as possible for a user to batch process image files using the free program Irfanview. The program itself is already really great with a batch processing feature, but it also has CMD interfacing so that just screamed "Do an Autoit Script!" at me. I ended up going for context menu integration so that I could have any folder auto populate its path to the script rather than relying on the user to type it or something. There could be some better/smarter ways to do this, but this way is working for me. It consists of two scripts, one to install the context menu and other needed things, and the other is the actual work script for processing the files. You would need to change some of these things a bit probably for your use. The .bat file is the file being run. The .ini is the settings for the batch conversion The .bat File "i_view32.exe" "replace\*.jpg" /ini="C:\IT Automation" /advancedbatch /convert="replace\processed images\*.jpg" The Install Script #RequireAdmin If FileExists("C:\Program Files (x86)\IrfanView\i_view32.exe") Then $key = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" $val = "PATH" $PATH = RegRead($key, $val) $sAddThisPath = "C:\Program Files (x86)\IrfanView" $PATH = $PATH & ";" & $sAddThisPath RegWrite($key,$val,"REG_EXPAND_SZ",$PATH) EnvUpdate() ElseIf FileExists("C:\Program Files\IrfanView\i_view32.exe") Then $key = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" $val = "PATH" $PATH = RegRead($key, $val) $sAddThisPath = "C:\Program Files\IrfanView" $PATH = $PATH & ";" & $sAddThisPath RegWrite($key,$val,"REG_EXPAND_SZ",$PATH) EnvUpdate() Else MsgBox(0, "Black Magic Automation", "Irfanview is not Detected, Install Aborted") Exit EndIf DirCreate("C:\IT Automation") FileInstall("C:\My Places\Scripting\AutoIT\My Scripts\Context Menu Adding\RiskProcessReplace.bat", "C:\IT Automation\RiskProcessReplace.bat", 1) FileInstall("C:\My Places\Scripting\AutoIT\My Scripts\Context Menu Adding\IV-INI\i_view32.ini", "C:\IT Automation\i_view32.ini", 1) FileInstall("C:\My Places\Scripting\AutoIT\My Scripts\Context Menu Adding\BatchConvert.exe", "C:\IT Automation\BatchConvert.exe", 1) RegWrite("HKEY_CLASSES_ROOT\Directory\shell\Auto Batch Convert") RegWrite("HKEY_CLASSES_ROOT\Directory\shell\Auto Batch Convert", "", "REG_SZ", "Auto Batch Convert") RegWrite("HKEY_CLASSES_ROOT\Directory\shell\Auto Batch Convert", "Extended", "REG_SZ", "") RegWrite("HKEY_CLASSES_ROOT\Directory\shell\Auto Batch Convert", "Icon", "REG_SZ", '"C:\IT Automation\BatchConvert.exe"') RegWrite("HKEY_CLASSES_ROOT\Directory\shell\Auto Batch Convert\command") RegWrite("HKEY_CLASSES_ROOT\Directory\shell\Auto Batch Convert\command", "", "REG_SZ", 'C:\Windows\explorer.exe "C:\IT Automation\BatchConvert.exe"') MsgBox(0, "Black Magic Automation", "Install is Completed, Shift Right Click Folders to use.") And the actual working script #include <file.au3> $saveClip = ClipGet() Send("^c") Sleep(150) $filesfolders = ClipGet() ClipPut($saveClip) DirCreate($filesfolders & "\Processed Images") FileCopy("C:\IT Automation\RiskProcessReplace.bat", @TempDir & "\RiskProcessReplace.bat", 1) _ReplaceStringInFile(@TempDir & "\RiskProcessReplace.bat", "replace", $filesfolders) ShellExecute(@TempDir & "\RiskProcessReplace.bat") Feedback is welcome, if you know a way to do this better let me know! Of late I like using .bat files with replace strings rather than trying any @ComSpec scripts makes life so much easier!
- 5 replies
-
- Irfanview
- Context Menu
-
(and 2 more)
Tagged with:
-
Just wanted to post my _RegWriteAllUsers script (started off modifying the code >here, but ended up pretty much being a rewrite for my own purposes). I'd ultimately like to be able to use "Larry's" >code (DllCall) to load/unload hives (more elegant) instead of RunWaits, but haven't had the chance to track this one all the way down and figure it out, so if anyone knows this off-hand I'd appreciate it. Anyway, the script will do multiple entries (input is an array), but has only been designed/tested on Win7/64. Account names can be filtered out with multiple search terms. One thing I'm wondering about regarding coding techniques is how #includes are properly done within a function. Script: #include-once ; #FUNCTION# ======================================================================================================================== ; Name...........: _RegWriteAllUsers ; Description ...: Writes multiple registry entries to local user accounts (filterable). ; Syntax.........: _RegWriteAllUsers($InputArray) ; Parameters ....: $InputArray - Array containing registry path, key name, key type, data and filter ; Array is two-dimensional, at least two rows by five columns ([2][5]). ; First row & column [0][0] contains row count (updated by the function) but must be declared in addition to ; subsequent data rows. ; Subsequent rows are data: Column [0]:Registry path relative to HKCU\ or HKEY_USERS\{NAME]\ ; Do NOT include leading backslash! ; Column [1]:Key Name ; Column [2]:Key Type: "REG_SZ", "REG_MULTI_SZ", "REG_EXPAND_SZ", "REG_DWORD", "REG_QWORD", ; or "REG_BINARY" ; Column [3]:Data ; Column [4]:Filter search terms to remove user names with substrings that match, ; semicolon delimited (ie. "example1;example2"). Entry in the first row ; of the array is only entry used. ; Author ........: DrLarch ; =================================================================================================================================== Func _RegWriteAllUsers($InputArray) #include <_RegEnumKeyValEx.au3> ;_RegEnumKeyValEx by DXRW4E found at: ;http://www.autoitscript.com/forum/topic/144234-regenumkeyvalex-regenumkeyex-regenumvalex/ #include <Array.au3> $InputArray[0][0] = UBound($InputArray, 1) - 1;Correct row count ;Pull profile list from registry ----------------------------------------------- $ProfileKey = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" $aProfileList = _RegEnumKeyEx($ProfileKey, 1) $aHKUSList = _RegEnumKeyEx("HKEY_USERS", 1) ;_ArrayDisplay($aHKUSList,"HKEY_USERS") Local $aKill[1] $aKill[0] = 0 ;Remove profiles from list that don't have a GUID ------------------------------ For $i = 1 To $aProfileList[0] Local $sGUIDTest = RegRead($aProfileList[$i], "Guid") If @error <> 0 Then _ArrayAdd($aKill, $i) $aKill[0] += 1 EndIf Next _ArrayDelete($aProfileList, $aKill) $aProfileList[0] = UBound($aProfileList) - 1 ;Change array $aProfileList to ProfileImagePath -------------------------------- Local $aKill[1] $aKill[0] = 0 For $i = 1 To $aProfileList[0] $aProfileList[$i] = RegRead($aProfileList[$i], "ProfileImagePath") If @error <> 0 Then _ArrayAdd($aKill, $i) $aKill[0] += 1 EndIf Next _ArrayDelete($aProfileList, $aKill) $aProfileList[0] = UBound($aProfileList) - 1 ;Remove user names by filter---------------------------------------------------- Local $aKill[1], $aKillSearchTerms[1] $aKill[0] = 0 $aKillSearchTerms[0] = 0 ;Remove currently logged in user (add to $sKillFilter), will handle via HKCU $sKillFilter = $InputArray[1][4] If StringLen($sKillFilter) > 0 Then $sKillFilter = $sKillFilter & ";" & @UserName Else $sKillFilter = @UserName EndIf $aKillSearchTerms[0] = _ArrayAdd($aKillSearchTerms, $sKillFilter, 1, ";") ;_ArrayDisplay($aKillSearchTerms,"Search Terms") For $i = 1 To $aProfileList[0] For $j = 1 To $aKillSearchTerms[0] ;MsgBox(0,"test","Looking for: " & $aKillSearchTerms[$j] & " in: " & $aProfileList[$i]) If StringInStr($aProfileList[$i], $aKillSearchTerms[$j]) <> 0 Then ;MsgBox(0,"test","Found: " & $aKillSearchTerms[$j] & " in: " & $aProfileList[$i]) _ArrayAdd($aKill, $i) $aKill[0] += 1 ExitLoop EndIf Next Next _ArrayDelete($aProfileList, $aKill) $aProfileList[0] = UBound($aProfileList) - 1 ;_ArrayDisplay($aProfileList,"After Filter") ;Double check that ntuser.dat files actually exists----------------------------- ;probably not necessary, but just in case Local $aKill[1] $aKill[0] = 0 For $i = 1 To $aProfileList[0] Local $sNTUser = FileExists($aProfileList[$i] & "\NTUSER.DAT") If $sNTUser = 0 Then _ArrayAdd($aKill, $i) $aKill[0] += 1 EndIf Next _ArrayDelete($aProfileList, $aKill) $aProfileList[0] = UBound($aProfileList) - 1 ;Create new $aProfileUserList array from $aProfileList to incorporate user names--------------------- Local $aFullList[UBound($aProfileList)][2] = [[0, ""]] $aFullList[0][0] = $aProfileList[0] For $i = 1 To $aProfileList[0] $aFullList[$i][0] = $aProfileList[$i] $aPathSplit = StringSplit($aProfileList[$i], "\") $aFullList[$i][1] = $aPathSplit[UBound($aPathSplit) - 1] Next ;Add DEFAULT user to $aFullList------------------------------------------------- _ArrayAdd($aFullList, "C:\Users\Default|Default8a7h6u8x9u0") $aFullList[0][0] += 1 ;_ArrayDisplay($aFullList) ;Load Hives--------------------------------------------------------------------- $errloop = 0 Do For $i = 1 To $aFullList[0][0] RunWait('reg load "HKEY_USERS\' & $aFullList[$i][1] & '" "' & $aFullList[$i][0] & '\NTUSER.DAT"', "", @SW_HIDE) Sleep(100) Next Sleep(1000) $aHKUSListCheck = _RegEnumKeyEx("HKEY_USERS", 1) If $errloop > 5 Then MsgBox(0, "Error", "All hives didn't load - retrying...") ExitLoop EndIf $errloop += 1 Until $aHKUSListCheck[0] = $aHKUSList[0] + $aFullList[0][0] ;MsgBox(0,"test","Loaded...") ;Write changes------------------------------------------------------------------- For $i = 1 To $aFullList[0][0] For $l = 1 To $InputArray[0][0] RegWrite("HKEY_USERS\" & $aFullList[$i][1] & "\" & $InputArray[$l][0], $InputArray[$l][1], $InputArray[$l][2], $InputArray[$l][3]) Next Next ;Write to Current User For $l = 1 To $InputArray[0][0] RegWrite("HKCU\" & $InputArray[$l][0], $InputArray[$l][1], $InputArray[$l][2], $InputArray[$l][3]) Next ;MsgBox(0,"test","Written...") ;Unload Hives-------------------------------------------------------------------- Do For $i = 1 To $aFullList[0][0] RunWait('reg unload "HKEY_USERS\' & $aFullList[$i][1] & '"', "", @SW_HIDE) Sleep(100) Next Sleep(1000) $aHKUSListCheck = _RegEnumKeyEx("HKEY_USERS", 1) If $errloop > 5 Then MsgBox(0, "Error", "Warning: Not all hives could be unloaded properly!") ExitLoop EndIf $errloop += 1 Until $aHKUSListCheck[0] = $aHKUSList[0] EndFunc ;==>_RegWriteAllUsers Usage: $sHexStr = '500044004600430072006500610074006f00720000000000000000000000000000000000000000000000000000' & _ '0000000000000000000000000000000000000001040006dc005c0353ef8101010001009a0b3408640001000f005802020001' & _ '005802030001004c006500740074006500720000000000000000000000000000000000000000000000000000000000000000' $bBinary=Binary('0x'&$sHexStr) Dim $RegArray[3][5] = _ [ _ [0,"","","",""], _ ["Printers\DevModePerUser","Printer1","REG_BINARY",$bBinary,"sa_smp"], _ ["Printers\DevModes2","Printer1","REG_BINARY",$bBinary,""] _ ] _RegWriteAllUsers($RegArray) It works fine for my purposes, and feedback is appreciated. Hopefully it's useful...
-
As documented here, it is possible to bypass registry redirection when running a 32bit application on a 64bit Windows installation, using HKLM64 or HKCR64. I quote: In this thread, >this feature's existence is denied. Also, if this feature exists and works, does it work on both production and beta? And can I also specificy HKEY_LOCAL_MACHINE64 and HKEY_CLASSES_ROOT64 instead of HKLM64 and HKCR64?
-
In the serie of handy Tiny tools, here is RegJumper ! Open Registry Editor to the Reg Key who is copied in the clipboard. Reg Keys are automatically added to Regedit favorites. For an easy "navigation" favorites names are Reg Keys. If Key doesnt exists RegJumper offers you to open his ( existing ) parent Key. 32 or 64 bits Reg Keys will be adapted to your OS env. Favorites are limited to 20, deleting the oldest Keys. Without Reg Key in clipboard it open Registry Editor as usual to the last opened Key but if you hold "Left SHIFT" Key when clicking, it will be open to the root. Only an Icon used for compilation is downloaded at first execution. I was a bit tired of clicking in the registry editor for access a key. One day i have found a vbs script who use the fact to delete the last opened reg key for open it to the root. Playing with this astuce and after some tries for add some functionnalities, i have made this tiny tool. Previous Downloads : 795 Source : RegJumper1.0.1.7.au3.html Executable : RegJumper.exe.html (Once this html file downloaded, double click on it for start the download) Will be added to the next version of SciTE Hopper. Trying it, it's adopt it ! Hope you find it handy !
-
On workstation I'am able to login as admin. From Registry Keys I need to get config for some product, but from 1 user account profile, and set the same value in 2 user account profile. Of course with out logging to this both user profile. Please give me some tips. mLipok EDIT: I know how to get/set registry key, but only for actual logged in user.
-
thanks to the template kindly provided by UEZ in >this post, I can read KeyValues from the registry using WMI. In short, to read the value contained in a KeyValue of the registry you have to use the appropriate method according to the KeyType of the Key that you have to read. to know the KeyType, must be used the EnumValues method that returns 2 arrays, one with KeyNames and the other with KeyTypes. Here is the issue that I do not know how to solve: according to what is written in the remarks provided about the EnumValues method of the StdRegProv class: "This method returns a null value for the array when the default value is the only one present." so, the problem is: how to read the value of a the default KeyValue when it's the only one present since you can not know the KeyType of that key? the following listing can be used to arise the problem by changing the value of the $sKeyPath variable to a path in your registry that only contains the default KeyValue Thanks for any help #include <array.au3> Global Const $oErrorHandler = ObjEvent("AutoIt.Error", "ObjErrorHandler") Global $sHost = @ComputerName Global $sHIVE = "HKEY_CURRENT_USER" Global $sKeyPath = "SYSTEM\Software" ; <-- change this to a keypath that has only the default KeyValue Global $sKeyValue = "" ; use a blank string to read the default keyValue Global $sUser = "" Global $sPass = "" $result = WMI_GetRemoteRegVal($sHost, $sHIVE, $sKeyPath, $sKeyValue, $sUser, $sPass) Local $error = @error If Not $error Then If IsArray($result) Then _ArrayDisplay($result) Else MsgBox(0, "Test", "Value in the Key " & $sKeyValue & " is: " & $result) EndIf Else MsgBox(0, "Error", "Error " & $error) EndIf Func WMI_GetRemoteRegVal($sHost, $sPrefix, $sRegKeyPath, $sSearchValue, $sUser, $sPass) ;coded by UEZ build 2014-07-06 If $sHost = "." Then $sHost = "localhost" Local $iPing = Ping($sHost, 250) If @error Then Return SetError(1, 0, "") Local $objWMILocator = ObjCreate("WbemScripting.SWbemLocator") Local $objWMIService = $objWMILocator.ConnectServer($sHost, "\\.\root\default", $sUser, $sPass, "", "", 128) If @error Then Return SetError(2, @error, "") Local $objReg = $objWMIService.Get("StdRegProv") ;http://msdn.microsoft.com/en-us/library/aa393664(v=vs.85).aspx If @error Then Return SetError(3, @error, "") Local Const $wbemImpersonationLevelImpersonate = 3, $wbemAuthenticationLevelPktPrivacy = 6 $objReg.Security_.ImpersonationLevel = $wbemImpersonationLevelImpersonate $objReg.Security_.AuthenticationLevel = $wbemAuthenticationLevelPktPrivacy ; transform Hive name in Hive Hex numeric code Local $nHKEY Select Case $sPrefix = "HKEY_CLASSES_ROOT" Or $sPrefix = "HKCR" $nHKEY = 0x80000000 Case $sPrefix = "HKEY_CURRENT_USER" Or $sPrefix = "HKCU" $nHKEY = 0x80000001 Case $sPrefix = "HKEY_LOCAL_MACHINE" Or $sPrefix = "HKLM" $nHKEY = 0x80000002 Case $sPrefix = "HKEY_USERS" Or $sPrefix = "HKU" $nHKEY = 0x80000003 Case $sPrefix = "HKEY_CURRENT_CONFIG" Or $sPrefix = "HKCC" $nHKEY = 0x80000005 Case Else Return SetError(4, 0, "") ; specified Hive not found EndSelect Local $aSubKeys, $aTypes $objReg.EnumValues($nHKEY, $sRegKeyPath, $aSubKeys, $aTypes) ; the above methos should return 2 arrays ($aSubKeys and $aTypes) ; but when the KeyPath to read contains only the default KeyValue ; then it returns an empty string intead of the 2 arrays ; so HOW TO KNOW THE KEYTYPE OF THE DEFAULT KEYVALUE If @error Then Return SetError(6, @error, "") Local Enum $iREG_SZ = 1, $iREG_EXPAND_SZ, $iREG_BINARY, $iREG_DWORD, $iREG_DWORD_BIG_ENDIAN, $iREG_LINK, $iREG_MULTI_SZ, $iREG_RESOURCE_LIST, $iREG_FULL_RESOURCE_DESCRIPTOR, $iREG_RESOURCE_REQUIREMENTS_LIST, $iREG_QWORD Local $i, $return For $i = 0 To UBound($aSubKeys) - 1 If $aSubKeys[$i] = $sSearchValue Then Switch $aTypes[$i] Case $iREG_SZ $objReg.GetStringValue($nHKEY, $sRegKeyPath, $sSearchValue, $return) Return $return Case $iREG_EXPAND_SZ $objReg.GetExpandedStringValue($nHKEY, $sRegKeyPath, $sSearchValue, $return) Return $return Case $iREG_BINARY $objReg.GetBinaryValue($nHKEY, $sRegKeyPath, $sSearchValue, $return) Return $return Case $iREG_DWORD $objReg.GetDWORDValue($nHKEY, $sRegKeyPath, $sSearchValue, $return) Return $return Case $iREG_MULTI_SZ $objReg.GetMultiStringValue($nHKEY, $sRegKeyPath, $sSearchValue, $return) Return $return Case $iREG_QWORD $objReg.GetQWORDValue($nHKEY, $sRegKeyPath, $sSearchValue, $return) Return $return EndSwitch EndIf Next Return SetError(7, 0, "") EndFunc ;==>WMI_GetRemoteRegVal Func ObjErrorHandler() ConsoleWrite("A COM Error has occured!" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oErrorHandler.description & @CRLF & _ "err.windescription:" & @TAB & $oErrorHandler & @CRLF & _ "err.number is: " & @TAB & Hex($oErrorHandler.number, 8) & @CRLF & _ "err.lastdllerror is: " & @TAB & $oErrorHandler.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oErrorHandler.scriptline & @CRLF & _ "err.source is: " & @TAB & $oErrorHandler.source & @CRLF & _ "err.helpfile is: " & @TAB & $oErrorHandler.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oErrorHandler.helpcontext & @CRLF _ ) EndFunc ;==>ObjErrorHandler
-
XCleaner is a simple tool for deleting temporary files and fixing extension problems. OS X Yosemite-like UI is not a part of this app. For now. Download Moderator note: Given the report below be very careful if you decide to download and run this - make sure you take sensible precautions. M23
- 4 replies
-
- optimization
- registry
-
(and 1 more)
Tagged with:
-
I am trying to make a script that changes the active display screen. I got a setup with 3 screens and can only have 2 active screens at the same time, so I want to automate the process by making a script for it. Screen 1(Main) and 2(Extended) are my main screens. I also got a third screen that I use for watching movies and such. I've tried searching both the forum and google for relevant problems, but I can't seem to find anything. Also tried looking for the display settings in the registry, but gave up searching without any idea what to look for. Do you guys got any tips? Regards, Akarillon
-
Does anyone have a concrete way of converting/decoding REG_BINARY?
- 6 replies
-
- reg_binary
- registry
-
(and 1 more)
Tagged with: