Jump to content

Help me fix the errors in this script


Recommended Posts

Hi, I've been trying to figure out the what causes the script to fail.(Most of this is in Norwegian.. sorry, and it's VERY messy:P)

#RequireAdmin
#Include <FTP.au3>
#Include <Zip.au3>
$appdir = @appdatadir & "\ShellBackup\settings.ini"


If FileExists($appdir) Then
    $oZip = IniRead($appdir, "Local", "Zip", "NotFound")
$oLocalDest = IniRead($appdir, "Local", "dest", "NotFound")

$oIP = IniRead($appdir, "FTP", "IP", "NotFound")
$oUsername = IniRead($appdir, "FTP", "username", "NotFound")
$oPassword = IniRead($appdir, "FTP", "password", "NotFound")
$oPort = IniRead($appdir, "FTP", "port", "NotFound")
$oDest = IniRead($appdir, "FTP", "dest", "NotFound")
    Select
    Case $CmdLine[1] = "-web"
    $var = InputBox("Backup - Web", "Velg navn paa backup arkivet.", "", "")
    $name = $var & ".zip"
    $file = _Zip_Create(@appdatadir & "\ShellBackup\" & $name)
    _Zip_AddFolder($file, $CmdLine[2])
    $var1 = Ping("http://www.google.com", 2000)
    If $var1 Then; also possible:  If @error = 0 Then ...
    _FTPput($file, $oDest)
Else
    Msgbox(0,"Internett - Feil","En feil oppsto da programmet provde aa koble seg til internet: " & @error)
EndIf

    Case $CmdLine[1] = "-pc"
            $var = InputBox("Backup - PC", "Velg navn paa backup arkivet.", "", "")
    $name = $var & ".zip"
    $file = _Zip_Create(@appdatadir & "\ShellBackup\" & $name)
    _Zip_AddFolder($file, $CmdLine[2])
    sleep(3000)
    FileMove($file, $oLocalDest)
    Case $CmdLine[1] = "-settings"
_settings()         
EndSelect
Else
    install()
    endif

Func _settings()
;$iServerip
;$iServerUsername
;$iServerPassword
;$iServerPort
;$iServerDest
    $oZip = IniRead($appdir, "Local", "Zip", "NotFound")
$iLocalDest = IniRead($appdir, "Local", "dest", "NotFound")

$iServerip = IniRead($appdir, "FTP", "IP", "NotFound")
$iServerUsername = IniRead($appdir, "FTP", "username", "NotFound")
$oPassword = IniRead($appdir, "FTP", "password", "NotFound")
$iServerPort = IniRead($appdir, "FTP", "port", "NotFound")
$iServerDest = IniRead($appdir, "FTP", "dest", "NotFound")

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Innstillinger", 547, 182, 285, 114)
$Group1 = GUICtrlCreateGroup("FTP", 0, 0, 265, 137)
$Label2 = GUICtrlCreateLabel("Brukernavn:", 8, 64, 62, 17)
$passord = GUICtrlCreateInput("Passord", 88, 88, 169, 21)
$Label4 = GUICtrlCreateLabel("Server Port:", 8, 112, 60, 17)
$Label6 = GUICtrlCreateLabel("Plassering:", 8, 40, 55, 17)
$Dest = GUICtrlCreateInput($iServerDest, 88, 40, 121, 21)
GUICtrlSetTip(-1, "Maa starte med / og slutte med /")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Lokal", 264, 0, 281, 137)
$Label5 = GUICtrlCreateLabel("Backup Destinasjon:", 272, 24, 102, 17)
$LocalDest = GUICtrlCreateInput($iLocalDest, 376, 24, 145, 21)
$browse = GUICtrlCreateButton("Velg Mappe", 272, 48, 251, 25, 0)
$Zip = GUICtrlCreateCheckbox("Lagre hver backup i en komprimert fil", 272, 80, 193, 17)

If $oZip = 1 then
GUICtrlSetState(-1, $GUI_CHECKED)
Else
    GUICtrlSetState(-1, $GUI_UNCHECKED)
    endif
GUICtrlSetTip(-1, "Lagrer backup i en .Zip fil")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$uninstall = GUICtrlCreateButton("Avinstaller Programmet", 272, 104, 139, 25, 0)
$Label1 = GUICtrlCreateLabel("Server Adresse:", 8, 16, 79, 17)
$ipadresse = GUICtrlCreateInput($iServerip, 88, 16, 169, 21)
GUICtrlSetLimit(-1, 99)
$brukernavn = GUICtrlCreateInput($iServerUsername, 88, 64, 169, 21)
$Label3 = GUICtrlCreateLabel("Passord:", 8, 88, 69, 17)
$serverport = GUICtrlCreateInput($iServerPort, 88, 112, 57, 21)
GUICtrlSetTip(-1, "Standard serverport er 21")
$lagre = GUICtrlCreateButton("&Lagre og Lukk", 8, 136, 259, 25, 0)
$avbryt = GUICtrlCreateButton("&Avbryt", 264, 136, 275, 25, 0)
$status = _GUICtrlStatusBar_Create($Form1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $browse
            $var = FileSelectFolder("Velg 'Backup' Mappe.", "")
            If @error Then
    MsgBox(16,"Feil","Kunne ikke velge mappen")
Else
    GUICtrlSetData($LocalDest, $var)
EndIf
        Else
            
            endif
            
        Case $lagre
;$iServerip
;$iServerUsername
;$iServerPassword
;$iServerPort
;$iServerDest
        $sServerip = GUICtrlRead($ipadresse)
$sUserName = GUICtrlRead($iServerip)    
$sPassword = GUICtrlRead($iServerip)    
$sPort = GUICtrlRead($iServerip)    
$sFTPdest = GUICtrlRead($iServerip) 
$sLocalDest = GUICtrlRead($Dest)

$sZip = GUICtrlRead($Zip)   
If $sZip = $GUI_CHECKED Then
$ssZip = 1
else
$ssZip = 0
endif

IniWrite($appdir, "Local", "Zip", $ssZip)
;Settings -> FTP
IniWrite($appdir, "FTP", "IP", $sServerip)
IniWrite($appdir, "FTP", "username", $brukernavn)
IniWrite($appdir, "FTP", "password", $passord)
IniWrite($appdir, "FTP", "port", $serverport)
IniWrite($appdir, "FTP", "dest", $sFTPdest)
;FTP DONE

;Local Settings
IniWrite($appdir, "Local", "dest", $sLocalDest)
        Case $avbryt
            exit
        Case $uninstall
        _uninstall()    
    EndSwitch
WEnd
endfunc



Func install()
;$iServerip
;$iServerUsername
;$iServerPassword
;$iServerPort
;$iServerDest
    
    DirCreate(@appdatadir & "\ShellBackup")
;next line is not essential, but adds custom description, otherwise Context will be say "PCBackup"
RegWrite("HKCR\*\shell\PCBackup", "", 'REG_SZ', 'Backup paa PCen')
RegWrite("HKCR\*\shell\PCBackup\Command", "", 'REG_SZ', @ScriptFullPath & ' -pc "%1"')
RegWrite("HKCR\*\shell\WebBackup", "", 'REG_SZ', 'Backup paa Webserveren')
RegWrite("HKCR\*\shell\WebBackup\Command", "", 'REG_SZ', @ScriptFullPath & ' -web "%1"')    
RegWrite("HKCR\Folder\shell\PCBackup", "", 'REG_SZ', 'Backup paa PCen')
RegWrite("HKCR\Folder\shell\PCBackup\Command", "", 'REG_SZ', @ScriptFullPath & ' -pc "%1"')
RegWrite("HKCR\Folder\shell\WebBackup", "", 'REG_SZ', 'Backup paa Webserveren')
RegWrite("HKCR\Folder\shell\WebBackup\Command", "", 'REG_SZ', @ScriptFullPath & ' -web "%1"')

RegWrite("HKCR\Folder\shell\SettingsBackup", "", 'REG_SZ', 'ShellBackup Innstillinger')
RegWrite("HKCR\Folder\shell\SettingsBackup\Command", "", 'REG_SZ', @ScriptFullPath & ' -settings "%1"')
RegWrite("HKCR\*\shell\SettingsBackup", "", 'REG_SZ', 'ShellBackup Innstillinger')
RegWrite("HKCR\*\shell\SettingsBackup\Command", "", 'REG_SZ', @ScriptFullPath & ' -settings "%1"')

;Overall settings
IniWrite($appdir, "Local", "Zip", "0")
;Settings -> FTP
IniWrite($appdir, "FTP", "IP", "ftp.webside.no")
IniWrite($appdir, "FTP", "username", "Brukernavn")
IniWrite($appdir, "FTP", "password", "Passord")
IniWrite($appdir, "FTP", "port", "21")
IniWrite($appdir, "FTP", "dest", "\backup\")
;FTP DONE

;Local Settings
IniWrite($appdir, "Local", "dest", "C:\backup")
MsgBox(64,"Fullfort","Innstallasjonen ble fullfort, restarter programmet..")
exit
    EndFunc
    
Func _uninstall()
    
    FileDelete(@appdatadir & "\ShellBackup")
    RegDelete("HKCR\*\shell", "PCBackup")
    RegDelete("HKCR\*\shell", "WebBackup")
    RegDelete("HKCR\Folder\shell", "PCBackup")
    RegDelete("HKCR\Folder\shell", "WebBackup")
    RegDelete("HKCR\Folder\shell", "SettingsBackup")
    RegDelete("HKCR\*\shell", "SettingsBackup")
    MsgBox(64,"Fullfort","ShellBackup ble fjernet fra din datamaskin")
    Dim $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(68,"Restart","Systemet trenger aa restartes for at alle innstillingene kan bli fjernet")
Select
   Case $iMsgBoxAnswer = 6;Yes
shutdown(2)
   Case $iMsgBoxAnswer = 7;No
exit
EndSelect
    endfunc
    
Func FTPput($file, $ftpdest1)
    $Hand = _FTPOpen('myftp')
_FTPConnect($Hand, $oIP, $oUserName, $oPassword)
if @error then msgbox(0,"Feil","Kunne ikke koble til FTP serveren")
    _FtpPutFile($Hand, $file, $oDest1);Upload to top level directory with different file name
    _FTPClose($Hand)
    msgbox(0,"Fullfort","Backup fullfort")
    endfunc

Syntax Check:

>C:\Program Files\AutoIt3\SciTE\..\au3check.exe "C:\Users\CHCO\Desktop\shellbackup.au3"
AutoIt3 Syntax Checker v1.54.8  Copyright (c) Tylo 2007

C:\Program Files\AutoIt3\Include\Security.au3(59,1) : ERROR: syntax error
Func
^
C:\Users\CHCO\Desktop\shellbackup.au3(24,26) : ERROR: _FTPput(): undefined function.
    _FTPput($file, $oDest)
~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Users\CHCO\Desktop\shellbackup.au3(40,10) : ERROR: install(): undefined function.
    install()
    ~~~~~~~~^
C:\Users\CHCO\Desktop\shellbackup.au3 - 3 error(s), 0 warning(s)
>Exit code: 2   Time: 0.306

This is the error I get when I run it in SciTe:

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\CHCO\Desktop\shellbackup.au3"   
C:\Program Files\AutoIt3\Include\Security.au3 (59) : ==> "Func" statement has no matching "EndFunc".:
Func _Security__AdjustTokenPrivileges($hToken, $fDisableAll, $pNewState, $iBufferLen, $pPrevState = 0, $pRequired = 0)

>Exit code: 1   Time: 0.305
Edited by Chris86
Link to comment
Share on other sites

#RequireAdmin
#include <FTP.au3>
#include <Zip.au3>
$appdir = @AppDataDir & "\ShellBackup\settings.ini"


If FileExists($appdir) Then
    $oZip = IniRead($appdir, "Local", "Zip", "NotFound")
    $oLocalDest = IniRead($appdir, "Local", "dest", "NotFound")

    $oIP = IniRead($appdir, "FTP", "IP", "NotFound")
    $oUsername = IniRead($appdir, "FTP", "username", "NotFound")
    $oPassword = IniRead($appdir, "FTP", "password", "NotFound")
    $oPort = IniRead($appdir, "FTP", "port", "NotFound")
    $oDest = IniRead($appdir, "FTP", "dest", "NotFound")
    Select
        Case $CmdLine[1] = "-web"
            $var = InputBox("Backup - Web", "Velg navn paa backup arkivet.", "", "")
            $name = $var & ".zip"
            $file = _Zip_Create(@AppDataDir & "\ShellBackup\" & $name)
            _Zip_AddFolder($file, $CmdLine[2])
            $var1 = Ping("http://www.google.com", 2000)
            If $var1 Then; also possible:  If @error = 0 Then ...
                _FTPput($file, $oDest)
            Else
                MsgBox(0, "Internett - Feil", "En feil oppsto da programmet provde aa koble seg til internet: " & @error)
            EndIf

        Case $CmdLine[1] = "-pc"
            $var = InputBox("Backup - PC", "Velg navn paa backup arkivet.", "", "")
            $name = $var & ".zip"
            $file = _Zip_Create(@AppDataDir & "\ShellBackup\" & $name)
            _Zip_AddFolder($file, $CmdLine[2])
            Sleep(3000)
            FileMove($file, $oLocalDest)
        Case $CmdLine[1] = "-settings"
            _settings()
    EndSelect
Else
    install()
EndIf

Func _settings()
    ;$iServerip
    ;$iServerUsername
    ;$iServerPassword
    ;$iServerPort
    ;$iServerDest
    $oZip = IniRead($appdir, "Local", "Zip", "NotFound")
    $iLocalDest = IniRead($appdir, "Local", "dest", "NotFound")

    $iServerip = IniRead($appdir, "FTP", "IP", "NotFound")
    $iServerUsername = IniRead($appdir, "FTP", "username", "NotFound")
    $oPassword = IniRead($appdir, "FTP", "password", "NotFound")
    $iServerPort = IniRead($appdir, "FTP", "port", "NotFound")
    $iServerDest = IniRead($appdir, "FTP", "dest", "NotFound")

    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <GuiStatusBar.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>

    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Innstillinger", 547, 182, 285, 114)
    $Group1 = GUICtrlCreateGroup("FTP", 0, 0, 265, 137)
    $Label2 = GUICtrlCreateLabel("Brukernavn:", 8, 64, 62, 17)
    $passord = GUICtrlCreateInput("Passord", 88, 88, 169, 21)
    $Label4 = GUICtrlCreateLabel("Server Port:", 8, 112, 60, 17)
    $Label6 = GUICtrlCreateLabel("Plassering:", 8, 40, 55, 17)
    $Dest = GUICtrlCreateInput($iServerDest, 88, 40, 121, 21)
    GUICtrlSetTip(-1, "Maa starte med / og slutte med /")
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Group2 = GUICtrlCreateGroup("Lokal", 264, 0, 281, 137)
    $Label5 = GUICtrlCreateLabel("Backup Destinasjon:", 272, 24, 102, 17)
    $LocalDest = GUICtrlCreateInput($iLocalDest, 376, 24, 145, 21)
    $browse = GUICtrlCreateButton("Velg Mappe", 272, 48, 251, 25, 0)
    $Zip = GUICtrlCreateCheckbox("Lagre hver backup i en komprimert fil", 272, 80, 193, 17)

    If $oZip = 1 Then
        GUICtrlSetState(-1, $GUI_CHECKED)
    Else
        GUICtrlSetState(-1, $GUI_UNCHECKED)
    EndIf
    GUICtrlSetTip(-1, "Lagrer backup i en .Zip fil")
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $uninstall = GUICtrlCreateButton("Avinstaller Programmet", 272, 104, 139, 25, 0)
    $Label1 = GUICtrlCreateLabel("Server Adresse:", 8, 16, 79, 17)
    $ipadresse = GUICtrlCreateInput($iServerip, 88, 16, 169, 21)
    GUICtrlSetLimit(-1, 99)
    $brukernavn = GUICtrlCreateInput($iServerUsername, 88, 64, 169, 21)
    $Label3 = GUICtrlCreateLabel("Passord:", 8, 88, 69, 17)
    $serverport = GUICtrlCreateInput($iServerPort, 88, 112, 57, 21)
    GUICtrlSetTip(-1, "Standard serverport er 21")
    $lagre = GUICtrlCreateButton("&Lagre og Lukk", 8, 136, 259, 25, 0)
    $avbryt = GUICtrlCreateButton("&Avbryt", 264, 136, 275, 25, 0)
    $status = _GUICtrlStatusBar_Create($Form1)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $browse
                $var = FileSelectFolder("Velg 'Backup' Mappe.", "")
                If @error Then
                    MsgBox(16, "Feil", "Kunne ikke velge mappen")
                Else
                    GUICtrlSetData($LocalDest, $var)
                EndIf
            Case $lagre
                ;$iServerip
                ;$iServerUsername
                ;$iServerPassword
                ;$iServerPort
                ;$iServerDest
                $sServerip = GUICtrlRead($ipadresse)
                $sUserName = GUICtrlRead($iServerip)
                $sPassword = GUICtrlRead($iServerip)
                $sPort = GUICtrlRead($iServerip)
                $sFTPdest = GUICtrlRead($iServerip)
                $sLocalDest = GUICtrlRead($Dest)

                $sZip = GUICtrlRead($Zip)
                If $sZip = $GUI_CHECKED Then
                    $ssZip = 1
                Else
                    $ssZip = 0
                EndIf

                IniWrite($appdir, "Local", "Zip", $ssZip)
                ;Settings -> FTP
                IniWrite($appdir, "FTP", "IP", $sServerip)
                IniWrite($appdir, "FTP", "username", $brukernavn)
                IniWrite($appdir, "FTP", "password", $passord)
                IniWrite($appdir, "FTP", "port", $serverport)
                IniWrite($appdir, "FTP", "dest", $sFTPdest)
                ;FTP DONE

                ;Local Settings
                IniWrite($appdir, "Local", "dest", $sLocalDest)
            Case $avbryt
                Exit
            Case $uninstall
                _uninstall()
        EndSwitch
    WEnd
EndFunc   ;==>_settings



Func install()
    ;$iServerip
    ;$iServerUsername
    ;$iServerPassword
    ;$iServerPort
    ;$iServerDest

    DirCreate(@AppDataDir & "\ShellBackup")
    ;next line is not essential, but adds custom description, otherwise Context will be say "PCBackup"
    RegWrite("HKCR\*\shell\PCBackup", "", 'REG_SZ', 'Backup paa PCen')
    RegWrite("HKCR\*\shell\PCBackup\Command", "", 'REG_SZ', @ScriptFullPath & ' -pc "%1"')
    RegWrite("HKCR\*\shell\WebBackup", "", 'REG_SZ', 'Backup paa Webserveren')
    RegWrite("HKCR\*\shell\WebBackup\Command", "", 'REG_SZ', @ScriptFullPath & ' -web "%1"')
    RegWrite("HKCR\Folder\shell\PCBackup", "", 'REG_SZ', 'Backup paa PCen')
    RegWrite("HKCR\Folder\shell\PCBackup\Command", "", 'REG_SZ', @ScriptFullPath & ' -pc "%1"')
    RegWrite("HKCR\Folder\shell\WebBackup", "", 'REG_SZ', 'Backup paa Webserveren')
    RegWrite("HKCR\Folder\shell\WebBackup\Command", "", 'REG_SZ', @ScriptFullPath & ' -web "%1"')

    RegWrite("HKCR\Folder\shell\SettingsBackup", "", 'REG_SZ', 'ShellBackup Innstillinger')
    RegWrite("HKCR\Folder\shell\SettingsBackup\Command", "", 'REG_SZ', @ScriptFullPath & ' -settings "%1"')
    RegWrite("HKCR\*\shell\SettingsBackup", "", 'REG_SZ', 'ShellBackup Innstillinger')
    RegWrite("HKCR\*\shell\SettingsBackup\Command", "", 'REG_SZ', @ScriptFullPath & ' -settings "%1"')

    ;Overall settings
    IniWrite($appdir, "Local", "Zip", "0")
    ;Settings -> FTP
    IniWrite($appdir, "FTP", "IP", "ftp.webside.no")
    IniWrite($appdir, "FTP", "username", "Brukernavn")
    IniWrite($appdir, "FTP", "password", "Passord")
    IniWrite($appdir, "FTP", "port", "21")
    IniWrite($appdir, "FTP", "dest", "\backup\")
    ;FTP DONE

    ;Local Settings
    IniWrite($appdir, "Local", "dest", "C:\backup")
    MsgBox(64, "Fullfort", "Innstallasjonen ble fullfort, restarter programmet..")
    Exit
EndFunc   ;==>install

Func _uninstall()

    FileDelete(@AppDataDir & "\ShellBackup")
    RegDelete("HKCR\*\shell", "PCBackup")
    RegDelete("HKCR\*\shell", "WebBackup")
    RegDelete("HKCR\Folder\shell", "PCBackup")
    RegDelete("HKCR\Folder\shell", "WebBackup")
    RegDelete("HKCR\Folder\shell", "SettingsBackup")
    RegDelete("HKCR\*\shell", "SettingsBackup")
    MsgBox(64, "Fullfort", "ShellBackup ble fjernet fra din datamaskin")
    Dim $iMsgBoxAnswer
    $iMsgBoxAnswer = MsgBox(68, "Restart", "Systemet trenger aa restartes for at alle innstillingene kan bli fjernet")
    Select
        Case $iMsgBoxAnswer = 6;Yes
            Shutdown(2)
        Case $iMsgBoxAnswer = 7;No
            Exit
    EndSelect
EndFunc   ;==>_uninstall

Func FTPput($file, $ftpdest1)
    $Hand = _FTPOpen('myftp')
    _FTPConnect($Hand, $oIP, $oUsername, $oPassword)
    If @error Then MsgBox(0, "Feil", "Kunne ikke koble til FTP serveren")
    _FtpPutFile($Hand, $file, $oDest1) ;Upload to top level directory with different file name
    _FTPClose($Hand)
    MsgBox(0, "Fullfort", "Backup fullfort")
EndFunc   ;==>FTPput

You had two statements the ruin your outcome that needed fixing first

0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E

Link to comment
Share on other sites

Okay, first things first, move any "#include" lines in your script to the TOP of your script, you shouldn't be placing #include lines inside of your functions.

Second of all, open your script in SciTE, go up to Tools and click "Tidy AutoIt Source". It'll both cleanup your code's formatting and when I ran it on your original code it flagged all sorts of things as having problems. (basically you've probably got an if...endif statement that's not paired.

*Edit - Terarink's code worked fine once I moved the #include lines to the top of the script.. I did have to comment out the ftp and zip au3 files because I don't have them, so, if you still get errors after moving your #include lines, I would suspect the problem is with them.

*Edit2 - There's nothing wrong with your Security.au3 file btw.

Edited by exodius
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...