Jump to content

Recommended Posts

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

Link to comment
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.

Link to comment
Share on other sites

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

  • 1 month later...

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
Link to comment
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)

 

Link to comment
Share on other sites

  • Moderators

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

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

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

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

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

Link to comment
Share on other sites

  • Moderators

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]])
...

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

@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
Link to comment
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

 

Link to comment
Share on other sites

  • Moderators
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

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
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?

Link to comment
Share on other sites

  • Moderators

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.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

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...