AntonioGNAL Posted April 7, 2014 Posted April 7, 2014 (edited) Hi guys, I've been trying to create a registry key export for a while, but i'm hitting my head against a wall here. I've tried a huge amount of combinations for both: ShellExecuteWait & RunWait commands, but they never complete the task. expandcollapse popup;This is the reg key Global $targetHistory = "HKEY_CURRENT_USER\Software\Hewlett-Packard\HP Print Settings\Ubicación predeterminada\Target History" RegeditTH($logHandler, $regBackup, $targetHistory) Func RegeditTH($logHandler, $regBackup, $targetHistory) Local $THRegBkup = $regBackup & "ExportTH.bat" Local $THRegHandler Local $removeFile _FileWriteLog($logHandler, "INFORMATION: ExportTH.bat storage directory = " & $regBackup & "." & @CRLF) ; Create a file to write registry keys to. If Not _FileCreate($THRegBkup) Then ; Error flags: ; 1 - Error opening specified file ; 2 - File could not be written to ; [OPTIONAL] Display a pop-up message for notification, error creating the file ;MsgBox($MB_SYSTEMMODAL, "Error", " Error reating reg file. Error Code:" & @error & ".") _FileWriteLog($logHandler, "WARNING: Registry export file not created." & @CRLF) Else $THRegHandler = FileOpen ($THRegBkup ,$FO_APPEND) If $THRegHandler <> -1 Then _FileWriteLog($logHandler, "INFORMATION: Performing registry backup for Target History keys." & @CRLF) FileWrite($THRegHandler, "@echo off" & @CRLF) ;FileWrite($THRegHandler, "regedit.exe /e " & $regBackup & "TargetHistory.reg " & '"HKEY_CURRENT_USER\Software\Hewlett-Packard\HP Print Settings\Ubicación predeterminada\Target History"' & @CRLF) FileWrite($THRegHandler, "Reg export " & '"HKEY_CURRENT_USER\Software\Hewlett-Packard\HP Print Settings\Ubicación predeterminada\Target History" ' & $regBackup & "TargetHistory.reg " & "/y" & @CRLF) FileWrite($THRegHandler, "dir " & $regBackup & @CRLF) FileWrite($THRegHandler, "dir " & $regBackup & " >> " & $regBackup & "dir.txt" & @CRLF) FileWrite($THRegHandler, "pause" & @CRLF) FileWrite($THRegHandler, "exit /B" & @CRLF) FileWrite($THRegHandler, "exit" & @CRLF) FileClose($THRegHandler) ;RunWait(@ComSpec & " /k " & "regedit.exe /e " & $regBackup & "TargetHistory2.reg " & $targetHistory) ;ShellExecuteWait(@ComSpec , "/k regedit.exe /e " & $regBackup & "TargetHistory.reg " & $targetHistory) ;ShellExecuteWait(@ComSpec & " /c " & $THRegBkup, @SW_HIDE) RunWait(@ComSpec & " /c " & $THRegBkup) ; Error Flag is set to non-zero in case of failure If @error <> 0 Then _FileWriteLog($logHandler, "ERROR: Registry export failed." & @CRLF) Else _FileWriteLog($logHandler, "WARNING: ExportTH.bat file could not be opened." & @CRLF) EndIf $removeFile = FileDelete($THRegBkup) If $removeFile Then _FileWriteLog($logHandler, "INFORMATION: File " & $THRegBkup & " deleted." Else _FileWriteLog($logHandler, "WARNING: File " & $THRegBkup & " not deleted or it does not exist." EndIf EndIf ; Close the handle returned by FileOpen. FileClose($THRegHandler) EndFunc This is the function i'm using for the call. Since i was not going anywhere with the AutoIt direct executions, i even tried creating a bat/cmd file with the command for a reg export to create the reg file i needed. However, even running the bat file is not working for me. I mean, the bat is executed, as you can see i created a couple of "dir" commands to be prompted and sent to a file. And they are showing up, but the registry export is never being executed. The best i could get was a message saying it was impossible to locate the key, but i know with 100% certainty the key exists in that path (because i'm creating and deleting it all the time). Can anyone point out any possible mistakes? Here you can see the error message in the CMD prompt: Thanks! Edited April 7, 2014 by AntonioGNAL
Paramjeet Posted April 7, 2014 Posted April 7, 2014 (edited) ;modified little bit... try this expandcollapse popup ;This is the reg key #include <File.au3> Global $targetHistory = "HKEY_CURRENT_USER\Software\Hewlett-Packard\HP Print Settings\Ubicación predeterminada\Target History" Global $logHandler Global $regBackup RegeditTH($logHandler, $regBackup, $targetHistory) Func RegeditTH($logHandler, $regBackup, $targetHistory) Local $THRegBkup = $regBackup & "ExportTH.bat" Local $THRegHandler Local $removeFile _FileWriteLog($logHandler, "INFORMATION: ExportTH.bat storage directory = " & $regBackup & "." & @CRLF) ; Create a file to write registry keys to. If Not _FileCreate($THRegBkup) Then ; Error flags: ; 1 - Error opening specified file ; 2 - File could not be written to ; [OPTIONAL] Display a pop-up message for notification, error creating the file ;MsgBox($MB_SYSTEMMODAL, "Error", " Error reating reg file. Error Code:" & @error & ".") _FileWriteLog($logHandler, "WARNING: Registry export file not created." & @CRLF) Else $THRegHandler = FileOpen ($THRegBkup ,$FO_APPEND) If $THRegHandler <> -1 Then _FileWriteLog($logHandler, "INFORMATION: Performing registry backup for Target History keys." & @CRLF) FileWrite($THRegHandler, "@echo off" & @CRLF) ;FileWrite($THRegHandler, "regedit.exe /e " & $regBackup & "TargetHistory.reg " & '"HKEY_CURRENT_USER\Software\Hewlett-Packard\HP Print Settings\Ubicación predeterminada\Target History"' & @CRLF) FileWrite($THRegHandler, "Reg export " & '"HKEY_CURRENT_USER\Software\Hewlett-Packard\HP Print Settings\Ubicación predeterminada\Target History" ' & $regBackup & "TargetHistory.reg " & "/y" & @CRLF) FileWrite($THRegHandler, "dir " & $regBackup & @CRLF) FileWrite($THRegHandler, "dir " & $regBackup & " >> " & $regBackup & "dir.txt" & @CRLF) FileWrite($THRegHandler, "pause" & @CRLF) FileWrite($THRegHandler, "exit /B" & @CRLF) FileWrite($THRegHandler, "exit" & @CRLF) FileClose($THRegHandler) ;RunWait(@ComSpec & " /k " & "regedit.exe /e " & $regBackup & "TargetHistory2.reg " & $targetHistory) ;ShellExecuteWait(@ComSpec , "/k regedit.exe /e " & $regBackup & "TargetHistory.reg " & $targetHistory) ;ShellExecuteWait(@ComSpec & " /c " & $THRegBkup, @SW_HIDE) RunWait(@ComSpec & " /c " & $THRegBkup) ; Error Flag is set to non-zero in case of failure If @error <> 0 Then _FileWriteLog($logHandler, "ERROR: Registry export failed." & @CRLF) Else _FileWriteLog($logHandler, "WARNING: ExportTH.bat file could not be opened." & @CRLF) EndIf $removeFile = FileDelete($THRegBkup) If $removeFile Then _FileWriteLog($logHandler, "INFORMATION: File " & $THRegBkup & " deleted." Else _FileWriteLog($logHandler, "WARNING: File " & $THRegBkup & " not deleted or it does not exist." EndIf EndIf ; Close the handle returned by FileOpen. FileClose($THRegHandler) EndFunc Edited April 7, 2014 by Melba23 Added code tags
Moderators Melba23 Posted April 7, 2014 Moderators Posted April 7, 2014 Paramjeet,Welcome to the AutoIt forum. When you post code please use Code tags - see here how to do it. Then you get a scrolling box and syntax colouring as you can see above now I have added the tags. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
AntonioGNAL Posted April 7, 2014 Author Posted April 7, 2014 (edited) ;modified little bit... try this expandcollapse popup ;This is the reg key #include <File.au3> Global $targetHistory = "HKEY_CURRENT_USER\Software\Hewlett-Packard\HP Print Settings\Ubicación predeterminada\Target History" Global $logHandler Global $regBackup RegeditTH($logHandler, $regBackup, $targetHistory) Func RegeditTH($logHandler, $regBackup, $targetHistory) Local $THRegBkup = $regBackup & "ExportTH.bat" Local $THRegHandler Local $removeFile _FileWriteLog($logHandler, "INFORMATION: ExportTH.bat storage directory = " & $regBackup & "." & @CRLF) ; Create a file to write registry keys to. If Not _FileCreate($THRegBkup) Then ; Error flags: ; 1 - Error opening specified file ; 2 - File could not be written to ; [OPTIONAL] Display a pop-up message for notification, error creating the file ;MsgBox($MB_SYSTEMMODAL, "Error", " Error reating reg file. Error Code:" & @error & ".") _FileWriteLog($logHandler, "WARNING: Registry export file not created." & @CRLF) Else $THRegHandler = FileOpen ($THRegBkup ,$FO_APPEND) If $THRegHandler <> -1 Then _FileWriteLog($logHandler, "INFORMATION: Performing registry backup for Target History keys." & @CRLF) FileWrite($THRegHandler, "@echo off" & @CRLF) ;FileWrite($THRegHandler, "regedit.exe /e " & $regBackup & "TargetHistory.reg " & '"HKEY_CURRENT_USER\Software\Hewlett-Packard\HP Print Settings\Ubicación predeterminada\Target History"' & @CRLF) FileWrite($THRegHandler, "Reg export " & '"HKEY_CURRENT_USER\Software\Hewlett-Packard\HP Print Settings\Ubicación predeterminada\Target History" ' & $regBackup & "TargetHistory.reg " & "/y" & @CRLF) FileWrite($THRegHandler, "dir " & $regBackup & @CRLF) FileWrite($THRegHandler, "dir " & $regBackup & " >> " & $regBackup & "dir.txt" & @CRLF) FileWrite($THRegHandler, "pause" & @CRLF) FileWrite($THRegHandler, "exit /B" & @CRLF) FileWrite($THRegHandler, "exit" & @CRLF) FileClose($THRegHandler) ;RunWait(@ComSpec & " /k " & "regedit.exe /e " & $regBackup & "TargetHistory2.reg " & $targetHistory) ;ShellExecuteWait(@ComSpec , "/k regedit.exe /e " & $regBackup & "TargetHistory.reg " & $targetHistory) ;ShellExecuteWait(@ComSpec & " /c " & $THRegBkup, @SW_HIDE) RunWait(@ComSpec & " /c " & $THRegBkup) ; Error Flag is set to non-zero in case of failure If @error <> 0 Then _FileWriteLog($logHandler, "ERROR: Registry export failed." & @CRLF) Else _FileWriteLog($logHandler, "WARNING: ExportTH.bat file could not be opened." & @CRLF) EndIf $removeFile = FileDelete($THRegBkup) If $removeFile Then _FileWriteLog($logHandler, "INFORMATION: File " & $THRegBkup & " deleted." Else _FileWriteLog($logHandler, "WARNING: File " & $THRegBkup & " not deleted or it does not exist." EndIf EndIf ; Close the handle returned by FileOpen. FileClose($THRegHandler) EndFunc Hi Paramjeet, Thanks for your answer. I already have the includes and other variables in the code, i just didn't write everything because it would take too much space. I did something i was afraid might work and it did... instead of exporting the key: HKEY_CURRENT_USERSoftwareHewlett-PackardHP Print SettingsUbicación predeterminadaTarget History I exported the key: HKEY_CURRENT_USERSoftwareHewlett-PackardHP Print Settings And the reg file automatically appeared when i executed the program. So there's something wrong with that key name which i'm unable to find. I also have an issue here: Local $removeFile $removeFile = FileDelete($THRegBkup) If $removeFile Then _FileWriteLog($logHandler, "INFORMATION: File " & $THRegBkup & " deleted." Else _FileWriteLog($logHandler, "WARNING: File " & $THRegBkup & " not deleted or it does not exist." EndIf I don't know why, but i get this error: It's strange because in the function description i saw a really similar code: ; Delete the temporary file. Local $iDelete = FileDelete($sFilePath) ; Display a message of whether the file was deleted. If $iDelete Then MsgBox($MB_SYSTEMMODAL, "", "The file was successfuly deleted.") Else MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst deleting the file.") EndIf Any ideas? Edited April 7, 2014 by AntonioGNAL
Solution Palestinian Posted April 7, 2014 Solution Posted April 7, 2014 Local $removeFile $removeFile = FileDelete($THRegBkup) If $removeFile Then _FileWriteLog($logHandler, "INFORMATION: File " & $THRegBkup & " deleted.") Else _FileWriteLog($logHandler, "WARNING: File " & $THRegBkup & " not deleted or it does not exist.") EndIf You forgot to close the brackets. AntonioGNAL 1
AntonioGNAL Posted April 7, 2014 Author Posted April 7, 2014 Local $removeFile $removeFile = FileDelete($THRegBkup) If $removeFile Then _FileWriteLog($logHandler, "INFORMATION: File " & $THRegBkup & " deleted.") Else _FileWriteLog($logHandler, "WARNING: File " & $THRegBkup & " not deleted or it does not exist.") EndIf You forgot to close the brackets. Oh my God!!! Thanks, i was so obsessed about the conditions i didn't even think about that.
sahsanu Posted April 7, 2014 Posted April 7, 2014 I did something i was afraid might work and it did... instead of exporting the key: HKEY_CURRENT_USERSoftwareHewlett-PackardHP Print SettingsUbicación predeterminadaTarget History I exported the key: HKEY_CURRENT_USERSoftwareHewlett-PackardHP Print Settings And the reg file automatically appeared when i executed the program. So there's something wrong with that key name which i'm unable to find. To try to solve this issue with accents in the RegKey name, change this on your script: RunWait(@ComSpec & " /c " & $THRegBkup) to RunWait(@ComSpec & " /c chcp 1250 && " & $THRegBkup) And try again. Un saludo, sahsanu
meows Posted June 29, 2014 Posted June 29, 2014 (edited) woops I misunderstood what you were doing,, '?do=embed' frameborder='0' data-embedContent>> is the way I found I do not know if this fits your issue but being it is a registry matter, I after 3 months of massive reading and testing find a answer to adding a VAR to the registry.. I stripped what I had to and there isn't any checking for keystroke issues with the input box.. user can input ANYTHING so if you use it add security to the input box COPY and paste,, it runs as advertised.. It will add 2 different VAR to the registry and a text file to the desktop expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=cps250.ico #AutoIt3Wrapper_Outfile=EvalYES.exe #AutoIt3Wrapper_Res_Comment= equal to #AutoIt3Wrapper_Res_Description=overlord #AutoIt3Wrapper_Res_Fileversion=12.0.0.0 #AutoIt3Wrapper_Res_LegalCopyright=reardon studio #AutoIt3Wrapper_Res_Language=1033 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ; *** Start added by AutoIt3Wrapper *** #include <FontConstants.au3> ; *** End added by AutoIt3Wrapper *** ;SciTE ;Version 3.3.7 ; Dec 12 2013 20:45:19 #include "ExtMsgBox.au3" #include <MsgBoxConstants.au3> #include <FileConstants.au3> #include<string.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiTab.au3> #include <Misc.au3> #include <ColorConstants.au3> #include <GuiButton.au3> #include <ExtMsgBox.au3> #include <constants.au3> #include <WinAPI.au3> $Regit1 = GUICreate("reg1", 621, 442, 192, 114) ;Opt("GUIOnEventMode", 1) Local Const $1Font = "Tahoma" $hButton1 = GUICtrlCreateButton("Register ", 20, 20, 1, 1, GUISetState(@SW_HIDE)) $hButton6 = GUICtrlCreateButton("Read Me", 20, 20, 1, 1, GUISetState(@SW_HIDE)) $hButton7 = GUICtrlCreateButton("Exit", 20, 20, 1, 1, GUISetState(@SW_HIDE)) GUICtrlSetState($hButton1, @SW_HIDE) GUISetState(@SW_SHOW, $Regit1) Button1Click() Button6Click() Button7Click() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $hButton1 Button1Click() Case $hButton6 Button6Click() Case $hButton7 Exit Button7Click() EndSwitch WEnd Func Button6Click() Local $securityCodeEncryptionKey = "SonoM1EXHardBonus" ;this must match the applications key $str = InputBox("EXHard Registration", "Register to try for SonoM1 Full version Download for Free Input first and last name") If @error = 1 Then Exit $Generate = StringUpper(StringRight($str, 5)) $restore = StringUpper(_StringEncrypt(1, $Generate, $securityCodeEncryptionKey, 1)) ClipPut($restore) MsgBox(0, "EXHard", "The registration code is: " & $restore & "Your code has been placed on the DESKTOP BONUS.TXT and clipboard You can paste it into a text file to save it") Local $sEvalString1 = Eval("$restore") #forceref $restore IniWrite(@DesktopCommonDir & "\BONUS.TXT", "General", "registration", $restore) Local $sString = DriveGetSerial(@HomeDrive & "\") ; Find the serial number of the home drive, generally this is the C:\ drive. #forceref $sString RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\RegisteredApplications", "CoreMaker", "REG_MULTI_SZ", "SOFTWARE\Coremaker\SonoM1\BonusAttempt\ControlCenter\Capabilities\" & $sString) RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\RegisteredApplications", "CoreVersion", "REG_MULTI_SZ", "SOFTWARE\Coremaker\SonoM1\" & $restore) FileCopy(@DesktopCommonDir & "BONUS.TXT", @AppDataCommonDir & "\BONUS.TXT", $FC_OVERWRITE + $FC_CREATEPATH) EndFunc ;==>Button6Click Func Button1Click() GUICtrlSetState($hButton1, $GUI_ENABLE) $answer = MsgBox(4, "Get SonoM1 Full Verson for Free", "Get EXHard. ") If $answer = 7 Then MsgBox(0, "", "OK. Bye!") Exit EndIf EndFunc ;==>Button1Click Func Button7Click() Exit EndFunc ;==>Button7Click Edited June 29, 2014 by meows
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now