Hello,
I will start off by saying that I'm a self taught hobbyist programmer, and new to Autoit. I apologize pretense if my technical terminology and usage is incorrect. A lot of reading and fiddling around on Google while I learn Autoit. The help file has been an outstanding resource. Anyways, I thought I should state that before asking my next question.
I have some functions that are meant to convert and store Autoit expressions in binary form in the Windows registry. When the function is needed the binary data is retrieved from the Windows registry key, converted back to a string, and passed through Execute() Everything works the way it should as long as there is only one expression on one line otherwise with multiple expressions Execute() does not behave the way I want it to. The only thing my little programming knowledge and common sense can come up with is that the Execute() must be passed through an array of sorts.
Included below is the UDF, GUI, & 2 examples. _EXAMPLES_1.au3 works as it should _EXAMPLES_2.au3 demonstrates the problem more clearly. The function is in RegApp_UDF.au3 on line 36. The GUI is meant to help automate the functions in the UDF. As always thank you for your assistance.
RegApp_UDF.au3
RegApp_GUI.au3
_EXAMPLES_1.au3
_EXAMPLES_2.au3
Download:
RegApps.zip 3.14K
1 downloads
I will start off by saying that I'm a self taught hobbyist programmer, and new to Autoit. I apologize pretense if my technical terminology and usage is incorrect. A lot of reading and fiddling around on Google while I learn Autoit. The help file has been an outstanding resource. Anyways, I thought I should state that before asking my next question.
I have some functions that are meant to convert and store Autoit expressions in binary form in the Windows registry. When the function is needed the binary data is retrieved from the Windows registry key, converted back to a string, and passed through Execute() Everything works the way it should as long as there is only one expression on one line otherwise with multiple expressions Execute() does not behave the way I want it to. The only thing my little programming knowledge and common sense can come up with is that the Execute() must be passed through an array of sorts.
Included below is the UDF, GUI, & 2 examples. _EXAMPLES_1.au3 works as it should _EXAMPLES_2.au3 demonstrates the problem more clearly. The function is in RegApp_UDF.au3 on line 36. The GUI is meant to help automate the functions in the UDF. As always thank you for your assistance.
RegApp_UDF.au3
[ autoit ]
#include-once #include #include ; store the binary data in the clipboard ; $val = The name of the Autoit script to convert and store to clipboard Func _StoreRegApp($val) Local $file = FileOpen($val) While 1 Local $str = FileRead($file) If $str = '' Then ExitLoop Return ClipPut(_StringToHex($str)) WEnd FileClose($file) EndFunc ; write binary data to windows registry ; $val = File name or embeded string | $key = Registry key name | $ref = Value name | $mod = 0(File) 1(Embeded String) - optional Func _WriteRegApp($val, $key, $ref, $mod = 0) If $mod = 1 then Return RegWrite('HKEY_CURRENT_USER\Software\RBApplications\'&$key, $ref, 'REG_BINARY', $val) Else Local $file = FileOpen($val) While 1 Local $str = FileRead($file) If $str = '' Then ExitLoop Return RegWrite('HKEY_CURRENT_USER\Software\RBApplications\'&$key, $ref, 'REG_BINARY', _StringToHex($str)) WEnd FileClose($file) EndIf EndFunc ; convert and execute the specified registry binary data ; $key = Registry key name | $val = Registry string value Func _ExecuteRegApp($key, $val) $ret = RegRead('HKEY_CURRENT_USER\Software\RBApplications\'&$key, $val) Execute(_HexToString(BinaryToString($ret))) EndFunc
[ autoit ]
#include #include "RegApp_UDF.au3" ; a simple gui to help automate the udf Global $width = 320, $height = 40 $gui = GUICreate("Registry Applications", $width, $height, -1, -1) $button1 = GUICtrlCreateButton ("Store", 5, 5, 100, 30) $button2 = GUICtrlCreateButton ("Write", 110, 5, 100, 30) $button3 = GUICtrlCreateButton ("Execute", 215, 5, 100, 30) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $button1 Local $ret = FileOpenDialog('', @ScriptDir & "\", "All Files (*.*)", 1) _StoreRegApp($ret) If $ret = '' then ; do nothing Else MsgBox(64, 'Return Message', 'The contents of '&$ret&' has been stored to the clipboard. Use ctrl+v to paste the data where needed') EndIf Case $button2 Local $ret = FileOpenDialog('', @ScriptDir & "\", "All Files (*.*)", 1) Local $key = InputBox('Key Name', 'Specify the key name.'&@LF&'Example: MyKeyName', '', '') Local $ref = InputBox('Value Name', 'Specify the value name.'&@LF&'Example: MyScriptFunction', '', '') If $ret = '' or $ref = '' or $key = '' then ; do nothing Else _WriteRegApp($ret, $key, $ref) MsgBox(64, 'Return Message', $ret&' is stored in key '&$key&' under value '&$ref) EndIf Case $button3 Local $key = InputBox('Key Name', 'Specify the key name.'&@LF&'Example: MyKeyName', '', '') Local $ref = InputBox('Value Name', 'Specify the value name.'&@LF&'Example: MyScriptFunction', '', '') If $ret = '' or $key = '' then ; do nothing Else _ExecuteRegApp($key, $ref) EndIf EndSwitch WEnd
[ autoit ]
#include #include #include #include #include "RegApp_UDF.au3" ; a few examples Global $iMemo Global $BinMsgBox = '4D7367426F7828302C20275265676973747279' & _ '204175746F69742042696E617279204170706C' & _ '69636174696F6E204578616D706C65272C2027' & _ '5468697320697320616E206578616D706C6520' & _ '6F662072756E6E696E67206120636F6E766572' & _ '7465642062696E617279204175746F69742073' & _ '63726970742066756E6374696F6E2066726F6D' & _ '2057696E646F77732052656769737472792E2729' $gui = GUICreate("Examples", 320, 40, -1, -1) $button1 = GUICtrlCreateButton ("Example 1", 5, 5, 100, 30) $button2 = GUICtrlCreateButton ("Example 2", 110, 5, 100, 30) $button3 = GUICtrlCreateButton ("Example 3", 215, 5, 100, 30) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $button1 MsgBox(64, 'Example 1 - Store Application', 'Convert this script into binary data and store its contents in the clipboard.') _StoreRegApp('_EXAMPLES.au3') Local $ret = ClipGet() MsgBox(64, 'Converted Return Data', $ret) Case $button2 MsgBox(64, 'Example 2 - Write Application', 'Creates a registry application key with binary data.') _WriteRegApp($BinMsgBox, 'MsgBox_Example', 'MsgBox', 1) _RegJump('HKCU\Software\RBApplications\MsgBox_Example') Case $button3 MsgBox(64, 'Example 3 - Execute Application', 'Executes registry Autoit binary data that was set in Example 2.') _ExecuteRegApp('MsgBox_Example', 'MsgBox') RegDelete('HKCU\Software\RBApplications') EndSwitch WEnd ; credit to Yashied for the _RegJump function (http://www.autoitscript.com/forum/topic/117907-regjump/#entry820919) Func _RegJump($sKey) Local $Root, $Text = StringSplit($sKey, '\', 2) If IsArray($Text) Then $Text = $Text[0] Else $Text = $sKey EndIf Switch $Text Case 'HKEY_CLASSES_ROOT', 'HKEY_CURRENT_USER', 'HKEY_LOCAL_MACHINE', 'HKEY_USERS', 'HKEY_CURRENT_CONFIG' $Root = $Text Case 'HKCR' $Root = 'HKEY_CLASSES_ROOT' Case 'HKCU' $Root = 'HKEY_CURRENT_USER' Case 'HKLM' $Root = 'HKEY_LOCAL_MACHINE' Case 'HKU' $Root = 'HKEY_USERS' Case 'HKCC' $Root = 'HKEY_CURRENT_CONFIG' Case Else Return 0 EndSwitch Local $Class = '[CLASS:RegEdit_RegEdit]', $Delay = Opt('WinWaitDelay', 0) Local $Prev, $Result = 1 If WinExists($Class) Then WinClose($Class) If Not WinWaitClose($Class, '', 5) Then $Result = 0 EndIf EndIf If $Result Then $Prev = RegRead('HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit', 'Lastkey') If @error Then $Prev = 0 EndIf If Not RegWrite('HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit', 'Lastkey', 'REG_SZ', StringReplace($sKey, $Text, $Root, 1)) Then $Result = 0 Else If Not Run('regedit.exe') Then $Result = 0 If IsString($Prev) Then RegWrite('HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit', 'Lastkey', 'REG_SZ', $Prev) EndIf EndIf EndIf EndIf Opt('WinWaitDelay', $Delay) Return $Result EndFunc ;==>_RegJump
[ autoit ]
#include "RegApp_UDF.au3" #cs $embededData = msgbox(0, '', 'Hello') msgbox(0, '', 'World') #ce Global $embededData = '6D7367626F7828302C2027272C202748656C6C6F27290D0A6D7367626F7828302C2027272C2027576F726C642729' _WriteRegApp($embededData, 'ExampleApplication', 'MsgBox_1', 1) _ExecuteRegApp('ExampleApplication', 'MsgBox_1')
Download:
![Attached File](http://aut1.autoit-cdn.com/forum/public/style_extra/mime_types/stuffit.gif)