Jump to content

Impossible to run a reg export


Go to solution Solved by Palestinian,

Recommended Posts

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.

;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:

Execution_001_zps76e6049b.png

Thanks!

Edited by AntonioGNAL
Link to comment
Share on other sites

;modified little bit... try this

 

 
;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 by Melba23
Added code tags
Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

;modified little bit... try this

 

 
;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:

Execution_002_zps2027aac6.png

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 by AntonioGNAL
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

  • 2 months later...

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

#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 by meows
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...