kitoy

Export Registry

21 posts in this topic

#1 ·  Posted (edited)

Hi,

I found this script for exporting registry file as text from Smartee.

https://www.autoitscript.com/forum/topic/126953-export-several-registry-keys-into-one-file/

$path = @DesktopDir & "\registry.txt"
$cache = ""
ShellExecuteWait("regedit.exe", "/e "&$path&" HKEY_CLASSES_ROOT\.ico")
$cache &= FileRead($path)
ShellExecuteWait("regedit.exe", "/e "&$path&" HKEY_CLASSES_ROOT\.eml")
$cache &= FileRead($path)
ShellExecuteWait("regedit.exe", "/e "&$path&" HKEY_CLASSES_ROOT\.txt")
$cache &= FileRead($path)
FileOpen($path, 2)
FileWrite($path, $cache)
FileClose($path)

However, it is not working in my end. I can only export blank text. I am trying to export the registry from a distiller.

I also noticed the extensions(.ico, .eml and .txt) at the end of the key. However, this is not available in the distiller. Any suggestions?

$path = @ScriptDir & "\registry.txt"
$cache = ""
ShellExecuteWait("regedit.exe", "/e "&$path&" HKEY_CURRENT_USER\Software\Adobe\Acrobat Distiller\10.0\WatchedFolders\")
$cache &= FileRead($path)
FileOpen($path, 2)
FileWrite($path, $cache)
FileClose($path)

 

Edited by kitoy

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Nevermind. Found the solution. :)

Edited by kitoy

Share this post


Link to post
Share on other sites
On 7/30/2016 at 1:11 AM, kitoy said:

Nevermind. Found the solution. :)

Care to share in case others come along with the need?

Share this post


Link to post
Share on other sites

Hi spudw2k,

I'm using RunWait instead of ShellExecuteWait.

RunWait(@ComSpec & ' /c reg EXPORT "HKEY_CURRENT_USER\Software\Adobe\Acrobat Distiller\10.0\WatchedFolders" registry.txt', @ScriptDir)

Here is my actual script.

#include <Array.au3>
#include <DateToday.au3>
#include <File.au3>

Local $distversion = "10.0"
Local $registry = 'HKEY_CURRENT_USER\Software\Adobe\Acrobat Distiller\'&$distversion&'\WatchedFolders'
Local $myip = @IPAddress1
Local $myregfile = "BackUpRegistry.reg"
Local $txtfile = $myip & "_Directories.txt"

If FileExists($txtfile) Then
    FileDelete($txtfile)
EndIf

;### Save distiller directories as text file.
For $i = 1 To 100
    $regpath = RegEnumKey($registry, $i)
    $list = FileOpen($txtfile, 1)
    If @error <> 0 Then ExitLoop
    FileWrite($list, $regpath & @CRLF)
Next

;### Copy available *.joboptions* based on document registry.
Local $count = _FileCountLines($txtfile)
For $a = 1 To $count
    $regpath = RegEnumKey($registry, $a)
    Local $jobops = @ScriptDir & "\" & "JobOptions_" & $newdate & "\" & $a
    Local $path = @ScriptDir & "\" & "JobOptions_" & $newdate & "\"
    DirCreate($jobops)
    FileCopy($regpath & "\*.joboptions*", $jobops)
Next

;### Export Watchfolders' registry file.
If FileExists($myregfile) Then
    FileDelete($myregfile) ;delete old registry file then replace a new one.
    RunWait(@ComSpec & ' /c reg EXPORT "'&$registry&'" '&$myregfile&'', @ScriptDir, @SW_HIDE)
Else
    RunWait(@ComSpec & ' /c reg EXPORT "'&$registry&'" '&$myregfile&'', @ScriptDir, @SW_HIDE)
EndIf

;### Move the text file and registration key inside the back-up folder.
If FileExists($txtfile) Then
    FileMove($txtfile, "JobOptions_" & $newdate, 1)
    If FileExists($myregfile) Then
        FileMove($myregfile, "JobOptions_" & $newdate, 1)
    EndIf
ElseIf @error Then
    MsgBox(4, "Error", "File not found.")
EndIf

;### Messagebox after (un)sucessful execution.
If @error Then
    MsgBox(16, "Error", "Back-up unsuccessful. Program will exit in 5 seconds", 5)
Else
    Sleep(500)
    MsgBox(64, "Success!", "Your back-up files can be found at:" & @CRLF & $path)
EndIf

I'm still trying to figure out on how to determine the version of the distiller as I'm planning to run the script from multiple versions. Maybe you have an idea?

Sorry for my bad scripting skills, I'm still new (a month or two) to this scripting world.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Fair enough, looking pretty decent for a beginner.  Thanks for taking the time to respond and explain your solution.  

 

edit: to get the version you should be able to enumerate it in the registry.  This is an example from the helpfile to step through a key and enumerate the subkeys.  Could be adapted to your script. Let me know if you need a hand.
 

#include <MsgBoxConstants.au3>

Local $sSubKey = ""
For $i = 1 To 10
    $sSubKey = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE", $i)
    If @error Then ExitLoop
    MsgBox($MB_SYSTEMMODAL, "SubKey #" & $i & " under HKLM\SOFTWARE: ", $sSubKey)
Next

 

Edited by spudw2k

Share this post


Link to post
Share on other sites

Thank you spudw2k. I will try this one.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I am about to finish my script  but I found the error, "Variable used without being declared." after compiling it and selecting another version not available in my drive.

I know there is something wrong with this code but I couldn't pinpoint the error. Please help.

#include <Array.au3>
#include <DateToday.au3> ;### udf
#include <File.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>

If _Singleton("test", 1) = 0 Then
    MsgBox(48, "Warning:", "Program is already active!", 10)
    Exit
EndIf

Opt("GUICloseOnESC", 0) ;1=ESC  closes, 0=ESC won't close

#region ### START Koda GUI section ### Form=
Global $_main = GUICreate("Distiller Backup Program", 291, 113, -1, -1)
Global $_run = GUICtrlCreateButton("R&un", 200, 72, 51, 25)
Global $dropSelect = GUICtrlCreateCombo("", 48, 40, 201, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "Adobe Acrobat Distiller 4|Adobe Acrobat Distiller 5|Adobe Acrobat Distiller 6|Adobe Acrobat Distiller 7|" _
         & "Adobe Acrobat Distiller 8|Adobe Acrobat Distiller 9|Adobe Acrobat Distiller X|Adobe Acrobat Distiller XI|Adobe Acrobat Distiller DC", "Adobe Acrobat Distiller X")
GUICtrlSetFont(-1, 11, 400, 0, "Calibri")
Global $Label1 = GUICtrlCreateLabel("Select Distiller Version", 50, 20, 150, 17)
GUICtrlSetFont(-1, 11, 400, 0, "Calibri")
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
TraySetIcon("icon.ico")
GUISetIcon("icon.ico")

Global $distversion

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $_run
            Switch GUICtrlRead($dropSelect)
                Case "Adobe Acrobat Distiller 4"
                    $distversion = "4.0"
                Case "Adobe Acrobat Distiller 5"
                    $distversion = "5.0"
                Case "Adobe Acrobat Distiller 6"
                    $distversion = "6.0"
                Case "Adobe Acrobat Distiller 7"
                    $distversion = "7.0"
                Case "Adobe Acrobat Distiller 8"
                    $distversion = "8.0"
                Case "Adobe Acrobat Distiller 9"
                    $distversion = "9.0"
                Case "Adobe Acrobat Distiller X"
                    $distversion = "10.0"
                Case "Adobe Acrobat Distiller XI"
                    $distversion = "11.0"
                Case "Adobe Acrobat Distiller DC"
                    $distversion = "DC"
            EndSwitch
            _runscript()
            Sleep(500)
            Exit
    EndSwitch
WEnd

Func _runscript()

    Global $registry = 'HKEY_CURRENT_USER\Software\Adobe\Acrobat Distiller\' & $distversion & '\WatchedFolders'
    Local $myip = @IPAddress1
    Local $myregfile = "BackUpRegistry.reg"
    Local $txtfile = $myip & "_Directories.txt"

    ;### List watchfolders in text file.
    For $i = 1 To 100
        $regpath = RegEnumKey($registry, $i)
        $list = FileOpen($txtfile, 1)
        If @error <> 0 Then ExitLoop
        FileWrite($list, $regpath & @CRLF)
    Next

    ;### Copy available *.joboptions* based on document registry.
    Local $count = _FileCountLines($txtfile)
    For $a = 1 To $count
        $regpath = RegEnumKey($registry, $a)
        Local $jobops = @ScriptDir & "\" & "JobOptions_" & $newdate & "\" & $a
        Local $path = @ScriptDir & "\" & "JobOptions_" & $newdate & "\"
        DirCreate($jobops)
        FileCopy($regpath & "\*.joboptions*", $jobops)
    Next

    ;### Export Watchfolders' registry file.
    If FileExists($myregfile) Then
        FileDelete($myregfile) ;delete old registry file then replace a new one.
        RunWait(@ComSpec & ' /c reg EXPORT "' & $registry & '" ' & $myregfile & '', @ScriptDir, @SW_HIDE)
    Else
        RunWait(@ComSpec & ' /c reg EXPORT "' & $registry & '" ' & $myregfile & '', @ScriptDir, @SW_HIDE)
    EndIf

    ;### Move the text file and registration key inside the back-up folder.
    If FileExists($txtfile) Then
        FileMove($txtfile, "JobOptions_" & $newdate, 1)
        If FileExists($myregfile) Then
            FileMove($myregfile, "JobOptions_" & $newdate, 1)
        EndIf
    ElseIf @error Then
        MsgBox(4, "Error", "File not found.")
    EndIf

    ;### Messagebox after (un)sucessful execution.
    If @error Then
        MsgBox(16, "Error", "Back-up unsuccessful. Program will exit in 5 seconds", 5)
    Else
        Sleep(500)
        MsgBox(64, "Success!", "Your back-up files can be found at:" & @CRLF & $path)
    EndIf
EndFunc   ;==>_runscript

 

 

Edited by kitoy
wrong attachment

Share this post


Link to post
Share on other sites

There is a non standard include missing:

>Running AU3Check (3.3.14.2)  from:C:\Program Files\AutoIt3  input:C:\Users\Bert\AutoIt3.My\Temp\test.au3
"C:\Users\Bert\AutoIt3.My\Temp\test.au3"(2,10) : error: can't open include file <DateToday.au3>.
#include <DateToday.au3>
~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\test.au3"(84,69) : warning: $newdate: possibly used before declaration.
        Local $jobops = @ScriptDir & "\" & "JobOptions_" & $newdate &
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\test.au3"(84,69) : error: $newdate: undeclared global variable.
        Local $jobops = @ScriptDir & "\" & "JobOptions_" & $newdate &
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Users\Bert\AutoIt3.My\Temp\test.au3 - 2 error(s), 1 warning(s)

 

Share this post


Link to post
Share on other sites

Hi AutoBert,

Sorry for not including that. Here it is.

#include <Date.au3>
$datenow =_NowDate()
$datesplit = StringSplit($datenow, "/")
$newdate = $datesplit[1] & "-" & $datesplit[2] & "-" & $datesplit[3]

 

Share this post


Link to post
Share on other sites

Couldn't you get the same in a single line with something like this:

@MON & "-" & @MDAY & "-" & @YEAR

 


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Yeah, I could. I'm still focusing on the other functions. After that, I will clean those redundant strings including this. My apologies.

Anyway, here it is.

#include <Array.au3>
#include <File.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>

If _Singleton("test", 1) = 0 Then
    MsgBox(48, "Warning:", "Program is already active!", 10)
    Exit
EndIf

Opt("GUICloseOnESC", 0) ;1=ESC  closes, 0=ESC won't close

#region ### START Koda GUI section ### Form=
Global $_main = GUICreate("Distiller Backup Program", 291, 113, -1, -1)
Global $_run = GUICtrlCreateButton("R&un", 200, 72, 51, 25)
Global $dropSelect = GUICtrlCreateCombo("", 48, 40, 201, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "Adobe Acrobat Distiller 4|Adobe Acrobat Distiller 5|Adobe Acrobat Distiller 6|Adobe Acrobat Distiller 7|" _
         & "Adobe Acrobat Distiller 8|Adobe Acrobat Distiller 9|Adobe Acrobat Distiller X|Adobe Acrobat Distiller XI|Adobe Acrobat Distiller DC", "Adobe Acrobat Distiller X")
GUICtrlSetFont(-1, 11, 400, 0, "Calibri")
Global $Label1 = GUICtrlCreateLabel("Select Distiller Version", 50, 20, 150, 17)
GUICtrlSetFont(-1, 11, 400, 0, "Calibri")
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
TraySetIcon("icon.ico")
GUISetIcon("icon.ico")

Global $distversion

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $_run
            Switch GUICtrlRead($dropSelect)
                Case "Adobe Acrobat Distiller 4"
                    $distversion = "4.0"
                Case "Adobe Acrobat Distiller 5"
                    $distversion = "5.0"
                Case "Adobe Acrobat Distiller 6"
                    $distversion = "6.0"
                Case "Adobe Acrobat Distiller 7"
                    $distversion = "7.0"
                Case "Adobe Acrobat Distiller 8"
                    $distversion = "8.0"
                Case "Adobe Acrobat Distiller 9"
                    $distversion = "9.0"
                Case "Adobe Acrobat Distiller X"
                    $distversion = "10.0"
                Case "Adobe Acrobat Distiller XI"
                    $distversion = "11.0"
                Case "Adobe Acrobat Distiller DC"
                    $distversion = "DC"
            EndSwitch
            _runscript()
            Sleep(500)
            Exit
    EndSwitch
WEnd

Func _runscript()

    Global $registry = 'HKEY_CURRENT_USER\Software\Adobe\Acrobat Distiller\' & $distversion & '\WatchedFolders'
    Local $myip = @IPAddress1
    Local $myregfile = "BackUpRegistry.reg"
    Local $txtfile = $myip & "_Directories.txt"
    Local $newdate = @MON & "-" & @MDAY & "-" & @YEAR

    ;### List watchfolders in text file.
    For $i = 1 To 100
        $regpath = RegEnumKey($registry, $i)
        $list = FileOpen($txtfile, 1)
        If @error <> 0 Then ExitLoop
        FileWrite($list, $regpath & @CRLF)
    Next

    ;### Copy available *.joboptions* based on document registry.
    Local $count = _FileCountLines($txtfile)
    For $a = 1 To $count
        $regpath = RegEnumKey($registry, $a)
        Local $jobops = @ScriptDir & "\" & "JobOptions_" & $newdate & "\" & $a
        Local $path = @ScriptDir & "\" & "JobOptions_" & $newdate & "\"
        DirCreate($jobops)
        FileCopy($regpath & "\*.joboptions*", $jobops)
    Next

    ;### Export Watchfolders' registry file.
    If FileExists($myregfile) Then
        FileDelete($myregfile) ;delete old registry file then replace a new one.
        RunWait(@ComSpec & ' /c reg EXPORT "' & $registry & '" ' & $myregfile & '', @ScriptDir, @SW_HIDE)
    Else
        RunWait(@ComSpec & ' /c reg EXPORT "' & $registry & '" ' & $myregfile & '', @ScriptDir, @SW_HIDE)
    EndIf

    ;### Move the text file and registration key inside the back-up folder.
    If FileExists($txtfile) Then
        FileMove($txtfile, "JobOptions_" & $newdate, 1)
        If FileExists($myregfile) Then
            FileMove($myregfile, "JobOptions_" & $newdate, 1)
        EndIf
    ElseIf @error Then
        MsgBox(4, "Error", "File not found.")
    EndIf

    ;### Messagebox after (un)sucessful execution.
    If @error Then
        MsgBox(16, "Error", "Back-up unsuccessful. Program will exit in 5 seconds", 5)
    Else
        Sleep(500)
        MsgBox(64, "Success!", "Your back-up files can be found at:" & @CRLF & $path)
    EndIf
EndFunc   ;==>_runscript

 

Edited by kitoy

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Update:

I created a loop to trap the error "Variable used without being declared."

Local $progfile = @ProgramFilesDir & "\Adobe\Acrobat " & $distversion

    If Not FileExists ($progfile) Then
        MsgBox(48, "WARNING!", "Incorrect version of distiller was selected." & @CRLF & "Please try again.")
        Call("_showgui")
    EndIf

Here is latest one.

#include <Array.au3>
#include <File.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>

If _Singleton("test", 1) = 0 Then
    MsgBox(48, "Warning:", "Program is already active!", 10)
    WinActivate("Distiller Backup Program")
    Exit
EndIf

Opt("GUICloseOnESC", 0) ;1=ESC  closes, 0=ESC won't close

#region ### START Koda GUI section ### Form=
Global $_main = GUICreate("Distiller Backup Program 1.0", 291, 113, -1, -1)
Global $_run = GUICtrlCreateButton("R&un", 200, 72, 51, 25)
Global $dropSelect = GUICtrlCreateCombo("", 48, 40, 201, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "Adobe Acrobat Distiller 4|Adobe Acrobat Distiller 5|Adobe Acrobat Distiller 6|Adobe Acrobat Distiller 7|" _
         & "Adobe Acrobat Distiller 8|Adobe Acrobat Distiller 9|Adobe Acrobat Distiller X|Adobe Acrobat Distiller XI|Adobe Acrobat Distiller DC", "Adobe Acrobat Distiller X")
GUICtrlSetFont(-1, 11, 400, 0, "Calibri")
Global $Label1 = GUICtrlCreateLabel("Select Distiller Version", 50, 20, 150, 17)
GUICtrlSetFont(-1, 11, 400, 0, "Calibri")
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

TraySetIcon("icon.ico")
GUISetIcon("icon.ico")

Global $distversion

_showgui()
Func _showgui()
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $_run
                Switch GUICtrlRead($dropSelect)
                    Case "Adobe Acrobat Distiller 4"
                        $distversion = "4.0"
                    Case "Adobe Acrobat Distiller 5"
                        $distversion = "5.0"
                    Case "Adobe Acrobat Distiller 6"
                        $distversion = "6.0"
                    Case "Adobe Acrobat Distiller 7"
                        $distversion = "7.0"
                    Case "Adobe Acrobat Distiller 8"
                        $distversion = "8.0"
                    Case "Adobe Acrobat Distiller 9"
                        $distversion = "9.0"
                    Case "Adobe Acrobat Distiller X"
                        $distversion = "10.0"
                    Case "Adobe Acrobat Distiller XI"
                        $distversion = "11.0"
                    Case "Adobe Acrobat Distiller DC"
                        $distversion = "DC"
                EndSwitch
                _runscript()
                Sleep(500)
                Exit
        EndSwitch
    WEnd
EndFunc

Func _runscript()

    Global $registry = 'HKEY_CURRENT_USER\Software\Adobe\Acrobat Distiller\' & $distversion & '\WatchedFolders'
    Local $myip = @IPAddress1
    Local $txtfile = $myip & "_Directories.txt"
    Local $newdate = @MON & "-" & @MDAY & "-" & @YEAR
    Local $myregfile = "BackUpRegistry_" & $newdate& ".reg"
    Local $progfile = @ProgramFilesDir & "\Adobe\Acrobat " & $distversion

    If Not FileExists ($progfile) Then
        MsgBox(48, "WARNING!", "Incorrect version of distiller was selected." & @CRLF & "Please try again.")
        Call("_showgui")
    EndIf

    ;### List watchfolders in text file.
    For $i = 1 To 100
        Local $regpath = RegEnumKey($registry, $i)
        $list = FileOpen($txtfile, 1)
        If @error <> 0 Then ExitLoop
        FileWrite($list, $regpath & @CRLF)
    Next

    ;### Copy available *.joboptions* based on document registry.
    Local $count = _FileCountLines($txtfile)
    For $a = 1 To $count
        If @OSVersion = "WIN_XP" Then ;Check if operating system is Windows XP or not. If yes, string "|" will be converted to "/" in the text file.
            $stringRep = _ReplaceStringInFile($txtfile, "|", "/")
        EndIf
        $regpath = RegEnumKey($registry, $a)
        Local $jobops = @ScriptDir & "\" & "JobOptions_" & $newdate & "\" & $a
        Local $path = @ScriptDir & "\" & "JobOptions_" & $newdate & "\"
        DirCreate($jobops)
        ;### Check if the distiller version is 5.0.
        If $distversion = "5.0" Then
                $stringRepRegX = StringReplace($regpath, "|", "/")
            FileCopy($stringRepRegX & "\*.joboptions*", $jobops)
        Else
            FileCopy($regpath & "\*.joboptions*", $jobops)
        EndIf
    Next

    ;### Export Watchfolders' registry file.
    If FileExists($myregfile) Then
        FileDelete($myregfile) ;delete old registry file, if available, then replaces a new one.
        RunWait(@ComSpec & ' /c reg EXPORT "' & $registry & '" ' & $myregfile & '', @ScriptDir, @SW_HIDE)
    Else
        RunWait(@ComSpec & ' /c reg EXPORT "' & $registry & '" ' & $myregfile & '', @ScriptDir, @SW_HIDE)
    EndIf

    ;### Move the text file and registration key inside the back-up folder.
    If FileExists($txtfile) Then
        FileMove($txtfile, "JobOptions_" & $newdate, 1)
        If FileExists($myregfile) Then
            FileMove($myregfile, "JobOptions_" & $newdate, 1)
        EndIf
    ElseIf @error Then
        MsgBox(48, "Error", $txtfile & " not found.")
        MsgBox(48, "Error", $myregfile & " not found.")
    EndIf

    ;### Messagebox after un/sucessful execution.
    If @error Then
        MsgBox(16, "Error", "Back-up unsuccessful. Program will exit in 5 seconds", 5)
    Else
        Sleep(500)
        MsgBox(64, "Success!", "Your back-up files can be found at:" & @CRLF & $path)
    EndIf
EndFunc   ;==>_runscript

 

Edited by kitoy

Share this post


Link to post
Share on other sites

You should just use Return instead of using the Call statement, you're recursing back to the calling function. Also, there's no need to use Call at all in this case, there's rarely a need to use it.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Some other suggestions. Rather than:

Case $_run
                Switch GUICtrlRead($dropSelect)
                    Case "Adobe Acrobat Distiller 4"
                        $distversion = "4.0"
                    Case "Adobe Acrobat Distiller 5"
                        $distversion = "5.0"
                    Case "Adobe Acrobat Distiller 6"
                        $distversion = "6.0"
                    Case "Adobe Acrobat Distiller 7"
                        $distversion = "7.0"
                    Case "Adobe Acrobat Distiller 8"
                        $distversion = "8.0"
                    Case "Adobe Acrobat Distiller 9"
                        $distversion = "9.0"
                    Case "Adobe Acrobat Distiller X"
                        $distversion = "10.0"
                    Case "Adobe Acrobat Distiller XI"
                        $distversion = "11.0"
                    Case "Adobe Acrobat Distiller DC"
                        $distversion = "DC"
                EndSwitch

Why not simplify:

GUICtrlSetData(-1, "Adobe Acrobat Distiller 4.0|Adobe Acrobat Distiller 5.0|Adobe Acrobat Distiller 6.0|Adobe Acrobat Distiller 7.0|" & _
                   "Adobe Acrobat Distiller 8.0|Adobe Acrobat Distiller 9.0|Adobe Acrobat Distiller X|Adobe Acrobat Distiller XI|Adobe Acrobat " & _
                   "Distiller DC", "Adobe Acrobat Distiller X")
...
...

Case $_run
   Local $aTemp = StringSplit(GUICtrlRead($dropSelect), " ")
   _runscript($aTemp[$aTemp[0]])
...

 


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

@BrewManNH, thanks for the suggestion. 

If Not FileExists ($progfile) Then
        MsgBox(48, "WARNING!", "Incorrect version of Acrobat Distiller was selected." & @CRLF & "Please try again.")
        Return $_run
    EndIf

@JLogan3o13, thanks for this. Here is what I came up to.

GUICtrlSetData(-1, "Adobe Acrobat Distiller 4|Adobe Acrobat Distiller 5|Adobe Acrobat Distiller 6|Adobe Acrobat Distiller 7|" & _
                "Adobe Acrobat Distiller 8|Adobe Acrobat Distiller 9|Adobe Acrobat Distiller 10|Adobe Acrobat Distiller 11|" & _
                "Adobe Acrobat Distiller DC", "Adobe Acrobat Distiller DC")

So I changed X to 10 and XI to 11 to avoid more loops. I also added ".0" since Program/Registry Files are using decimal points. i.e. 10.0, 11.0

Case $_run
       Local $aTemp = StringSplit(GUICtrlRead($dropSelect), " ")
            $distversion = ($aTemp[$aTemp[0]])
        If $distversion > 0 Then
            $distversion = $distversion & ".0"
        EndIf

I am also thinking to use .ini file so other people can easily add more versions in case new versions will be available. I will post it when I'm done.

Edited by kitoy

Share this post


Link to post
Share on other sites

Update: Here is the latest one using config file.

#include <Array.au3>
#include <File.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>

If _Singleton("test", 1) = 0 Then
    MsgBox(48, "Warning", "Program is already active!", 10)
    WinActivate("Distiller Backup Program")
    Exit
EndIf

Opt("GUICloseOnESC", 0) ;1=ESC  closes, 0=ESC won't close

#region ### START Koda GUI section ### Form=
Global $_main = GUICreate("Distiller Backup Program 1.0", 291, 113, -1, -1)
Global $_run = GUICtrlCreateButton("R&un", 200, 72, 51, 25)
Global $dropSelect = GUICtrlCreateCombo("", 48, 40, 201, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
$_config=  IniRead(@ScriptDir & "\config.ini", "Version", "Distill", "")
GUICtrlSetData(-1, $_config, "Adobe Acrobat Distiller DC")
GUICtrlSetFont(-1, 11, 400, 0, "Calibri")
Global $Label1 = GUICtrlCreateLabel("Select Distiller Version", 50, 20, 150, 17)
GUICtrlSetFont(-1, 11, 400, 0, "Calibri")
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

TraySetIcon("icon.ico")
GUISetIcon("icon.ico")

Global $distversion

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $_run
               Local $aTemp = StringSplit(GUICtrlRead($dropSelect), " ")
                $distversion = ($aTemp[$aTemp[0]])
            If $distversion > 0 Then
                $distversion = $distversion & ".0"
            EndIf
            _runscript()
        Sleep(500)
    EndSwitch
WEnd

Func _runscript()

    Global $registry = 'HKEY_CURRENT_USER\Software\Adobe\Acrobat Distiller\' & $distversion & '\WatchedFolders'
    Local $myip = @IPAddress1
    Local $txtfile = $myip & "_Directories.txt"
    Local $newdate = @MON & "-" & @MDAY & "-" & @YEAR
    Local $myregfile = "BackUpRegistry_" & $newdate& ".reg"
    Local $progfile = @ProgramFilesDir & "\Adobe\Acrobat " & $distversion

    If Not FileExists ($progfile) Then
        MsgBox(48, "WARNING!", "Incorrect version of Acrobat Distiller was selected." & @CRLF & "Please try again.")
        Return $_run
    EndIf

    ;### List watchfolders in text file.
    For $i = 1 To 100
        Local $regpath = RegEnumKey($registry, $i)
        $list = FileOpen($txtfile, 1)
        If @error <> 0 Then ExitLoop
        FileWrite($list, $regpath & @CRLF)
    Next

    ;### Copy available *.joboptions* based on document registry.
    Local $count = _FileCountLines($txtfile)
    For $a = 1 To $count
        If @OSVersion = "WIN_XP" Then ;Check if operating system is Windows XP or not. If yes, string "|" will be converted to "/" in the text file.
            $stringRep = _ReplaceStringInFile($txtfile, "|", "/")
        EndIf
        $regpath = RegEnumKey($registry, $a)
        Local $jobops = @ScriptDir & "\" & "JobOptions_" & $newdate & "\" & $a
        Local $path = @ScriptDir & "\" & "JobOptions_" & $newdate & "\"
        DirCreate($jobops)
        ;### Check if the distiller version is 5.0.
        If $distversion = "5.0" Then
                $stringRepRegX = StringReplace($regpath, "|", "/")
            FileCopy($stringRepRegX & "\*.joboptions*", $jobops)
        Else
            FileCopy($regpath & "\*.joboptions*", $jobops)
        EndIf
    Next

    ;### Export Watchfolders' registry file.
    If FileExists($myregfile) Then
        FileDelete($myregfile) ;delete old registry file, if available, then replaces a new one.
        RunWait(@ComSpec & ' /c reg EXPORT "' & $registry & '" ' & $myregfile & '', @ScriptDir, @SW_HIDE)
    Else
        RunWait(@ComSpec & ' /c reg EXPORT "' & $registry & '" ' & $myregfile & '', @ScriptDir, @SW_HIDE)
    EndIf

    ;### Move the text file and registration key inside the back-up folder.
    If FileExists($txtfile) Then
        FileMove($txtfile, "JobOptions_" & $newdate, 1)
        If FileExists($myregfile) Then
            FileMove($myregfile, "JobOptions_" & $newdate, 1)
        EndIf
    ElseIf @error Then
        MsgBox(48, "Error", $txtfile & " not found.")
        MsgBox(48, "Error", $myregfile & " not found.")
    EndIf

    ;### Messagebox after un/sucessful execution.
    If @error Then
        MsgBox(16, "Error", "Back-up unsuccessful. Program will exit in 5 seconds", 5)
    Else
;~      Sleep(500)
        MsgBox(64, "Success!", "Your back-up files can be found at:" & @CRLF & $path)
        Sleep(500)
        Exit ;# exit code after successful process.
    EndIf
EndFunc   ;==>_runscript

config.ini:

[Version]
Distill = Adobe Acrobat Distiller 4|Adobe Acrobat Distiller 5|Adobe Acrobat Distiller 6|Adobe Acrobat Distiller 7|Adobe Acrobat Distiller 8|Adobe Acrobat Distiller 9|Adobe Acrobat Distiller 10|Adobe Acrobat Distiller 11|Adobe Acrobat Distiller DC

 

Share this post


Link to post
Share on other sites
5 hours ago, kitoy said:

I am also thinking to use .ini file so other people can easily add more versions in case new versions will be available. I will post it when I'm done.

Makes sense, you could then read the file into an Array, and then simply do something like this to populate the control:

GUICtrlSetData(-1, _ArrayToString($aArray, "|"))

But, you could also save yourself the hassle of them having to choose the version, and just grab it yourself:

Local $sKey = "HKCU\SOFTWARE\Adobe"
Local $sSubKey, $sPath

    For $i = 1 To 100
        $sSubKey = RegEnumKey($sKey, $i)
            If @error Then
                ExitLoop
            Else
                If StringInStr($sSubKey, "Acrobat Distiller") Then
                    $sPath = $sKey & "\" & $sSubKey & "\WatchedFolders"
                EndIf
            EndIf
    Next

 


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
14 hours ago, JLogan3o13 said:

Makes sense, you could then read the file into an Array, and then simply do something like this to populate the control:

GUICtrlSetData(-1, _ArrayToString($aArray, "|"))

 

I'm sorry but how am I going to use _arraytostring to .ini file?

Share this post


Link to post
Share on other sites

I was intimating that if you used a file, you could read that file to an array, then use the line provided to fill your control with the data.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

I see. Sorry for misunderstanding.

Share this post


Link to post
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

  • Similar Content

    • Kidney
      By Kidney
      So i have this string that i am trying to split up into an array.
       
        {"q1":{"a2":[0,1],"a5":[0,0],"a3":[0,1],"a4":[0,0],"a1":[1,0]},"q2":{"a1":[1,1],"a2":[0,1]},"q3":{"a2":[1,0],"a4":[0,0],"a5":[0,0],"a3":[0,0],"a1":[0,1]},"q4":{"a2":[1,1],"a4":[0,1],"a1":[0,0],"a5":[0,1],"a3":0,0]},"q5":{"a1":[1,1],"a5":[0,1],"a4":[0,0],"a3":[0,0],"a2":[0,0]},"q6":{"a1":[1,1],"a4":[0,1],"a2":[0,1],"a3":[0,1]},"q7":{"a5":[1,0],"a3":[0,1],"a2":[0,1],"a1":[0,0],"a4":[0,1]},"q8":{"a3":[1,1],"a4":0,1],"a2":[0,1],"a1":[0,1]},"q9":{"a1":[1,0],"a2":[0,0]}}}} What i am trying to accomplish is build a RegExp that will output something very similar to this: $aArray[0] = "q1":{"a2":[0,1],"a5":[0,0],"a3":[0,1],"a4":[0,0],"a1":[1,0]}," $aArray[1] = "q2":{"a1":[1,1],"a2":[0,1]}, $aArray[3] = "q3":{"a2":[1,0],"a4":[0,0],"a5":[0,0],"a3":[0,0],"a1":[0,1]}, .... So you can see i pretty much want the StringRegExp to grab all of the information inbetween "q\d" Here is what i have done so far: #include <Array.au3> $hResults = FileOpen("Results.txt", 0) $sResults = FileRead($hResults) $aQuestions = StringRegExp($sResults, '"q\d{1,}.*', 3) ConsoleWrite(@error & @CRLF & @extended & @CRLF) _ArrayDisplay($aQuestions) The output i get is $aQuestions[0] with the entire string. I tried less greedy options for the '.' by adding ++ or +? but neither are working. 
      Hopefully i explained it well enough. Any help is appreciated!
    • matwachich
      By matwachich
      This UDF contains functions that help managing the configuration of your scripts.
      You can use either an *.ini file, or registry keys, the UDF manage for you all IniRead/IniWrite or RegRead/RegWrite calls.

      Instructions
      First, you must call _AutoCfg_Init to setup the system, which method will be used to stor the config (ini/reg), the path (ini file/reg key) and various options (data encryption, ini file section).
      After that, you must add the configuration entries that will be used, with their respective default value (use _AutoCfg_AddEntry).
      Next, you must call _AutoCfg_Update to update every entry with either it’s corresponding value on the disk (ini/reg) or with it’s default value if no value is present on the disk.
      Finally, you can use in your script the function CFG to get the current value of an entry, or an array of all the entries and their values and default values. And the function _AutoCfg_SetEntry the set the value of an entry or set it to it’s default value.
      UDF_autoCfg.zip