blumi

Error: Variable used without being declared

21 posts in this topic

When I try to run a script I get this message

Line 7516

File ....

Error: Variable used without being declared

 

The script has only 180 lines of code.

Can't autoit tell me which variable is used withoud being declared?

This would be very helpful.

 

Share this post


Link to post
Share on other sites



Okay with 3 included files

#include <file.au3>
#include <array.au3>
#include <EventLog.au3>

there should be more than 7000 lines of code.

In Scite the script runs fine without any errors.

Whe I compile it an run it on another pc the error message appears.

Any ideas?

Share this post


Link to post
Share on other sites

There is a difference between scite and a compiled script how to handle the variables?

What ist this good for?

Share this post


Link to post
Share on other sites

There is a difference between scite and a compiled script how to handle the variables?

What ist this good for?

Try to use this:

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7

 


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

Still the same error message

Error: Variable used without being declared

I am a little bit confused. Did some calc, the line where the error should be is code I have used often in other scripts, too, without any error messages.

What can I do ?

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Error: Variable used without being declared
So you just declare It.
 

Global $variable
If Not IsDeclared($variable) Then Global $variable

 

 

Like this is bad:

;It is not recommended, can call that was bad.
Global $variablex="xyz"
_Func()
Func _Func($variable=$variablex)
    ;warning: $variable possibly used before declaration.
EndFunc

 

Edited by Trong

Regards,
 

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

What can I do ?

Options:

  1. Install the full SciTE4AutoIt3 version and run au3stripper with the /mergeonly parameter, which will generate the source as is included in the compiled EXE.
  2. Post the script and let other look at what you did that might cause this.

Jos 

 

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

au2stripper

I think you thinking au3stripper ;)

EDIT: Jos was faster ;)

 

EDIT2:

I would also recommend to use 

#Au3Stripper_Parameters=/MO /RSLN

Edited by mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=\\xxx\Administration\AutoIt\Icons\Office 2013.ico
#AutoIt3Wrapper_Outfile=\\xxx\Administration\AutoIt\Installationsscripte\Office 2016 x86.exe
#AutoIt3Wrapper_Res_Fileversion=1.0.0.8
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
#AutoIt3Wrapper_Res_Language=1031
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7


;
; Programm:                 Office 2016 x86
; Datum:                        18.11.2015
; AutoIt3 Version:  3.3.14.1
;


#include <file.au3>
#include <array.au3>
#include <EventLog.au3>


$ScriptName     = "Office 2016 x86"
$ProgrammPfad   = "Programme\Installation\Office2016\x86\"
$ProgrammDatei  = "setup.exe"
$Parameter          = " /adminfile Office2016.MSP"
$ConfigPfad         = "\Administration\AutoIt\"
$ConfigFile         = "config.ini"


; Variablen für Eventlog
Local $hEventLog, $aData[4] = [3, 1, 2, 3]



; Lokale Konfiguration prüfen (Configfile liegt im Scriptverzeichnis)
If (FileExists(@ScriptDir & "\" & $ConfigFile)) Then
    $config = @ScriptDir & "\" & $ConfigFile
Else
    ; Netzwerkkonfiguration (Configfile liegt auf dem Server im Pfad \Administration\AutoIt\ von dem das Script ausgeführt wird)
    Dim $SplitDrive, $SplitDir, $SplitFileName, $SplitExtension
    $SplitPath      = _PathSplit (@ScriptFullPath, $SplitDrive, $SplitDir, $SplitFileName, $SplitExtension)
    $SplitServer    = $SplitPath[1]
    $config             = $SplitServer & $ConfigPfad & $ConfigFile
EndIf

; Konfiguration einlesen und Server definieren
If (FileExists($config)) Then

    ; Anzahl der Einträge im Bereich IP feststellen
    $aArray = IniReadSection($config, "IP")
    $counter = $aArray[0][0]

    ; Übereinstimmung der eigenen IP Adresse und den Vorgaben aus dem INI File überprüfen
    For $i = 1 To $counter
        If (StringInStr (@IPAddress1, $aArray[$i][1])) OR (StringInStr (@IPAddress2, $aArray[$i][1])) Then


            ; Standord aus dem Array auslesen. Das = Zeichen im String FR=10.112. trennt die Werte in Spalten
            $standort = $aArray[$i][0]

            ; Server anhand von $standort auslesen
            $server = IniRead ($config, "Server", $standort, "Fehler")

        EndIf
    Next

    ; Serverpfad anpassen, für weitere Verwendung
    $Server = "\\" & $server & "\"

Else
    MsgBox (16, $ScriptName, "Die Konfigurationsdatei " & $config & " wurde nicht gefunden.")
    $hEventLog = _EventLog__Open("", $ScriptName)
    _EventLog__Report($hEventLog, 1, 0, 2, "Administrator", "Die Konfigurationsdatei wurde nicht gefunden", $aData)
    _EventLog__Close($hEventLog)
    Exit(1)
EndIf





TrayTip($ScriptName & " - Installation", $ScriptName & " wird installiert. Bitte warten...", 2000)


; Clientkomponenten für Outlook Installation überprüfen
$string = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{7CDE44B1-0759-483A-924C-CB65DF98F5F8}", "DisplayName")
$pos = StringInStr($string, "Clientkomponenten")
If ($pos = 1) Then
    $CheckRegistry = True
Else
    $CheckRegistry = False
EndIf

; Clientkomponenten für Outlook deinstallieren
If ($CheckRegistry = True) Then
    MsgBox(64, $ScriptName, "Clientkomponenten für Outlook entdeck, wird nun deinstalliert", 3)
    RunWait('msiexec /qb- /x {7CDE44B1-0759-483A-924C-CB65DF98F5F8} /norestart')
    MsgBox(64, $ScriptName, "Clientkomponenten für Outlook wurden deinstalliert", 3)
EndIf



; Office 2010 Installation überprüfen
$string = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{90140000-0011-0000-0000-0000000FF1CE}", "DisplayName")
$pos = StringInStr($string, "Microsoft Office")
If ($pos = 1) Then
    $CheckRegistry = True
Else
    $CheckRegistry = False
EndIf

; Office 2010 deinstallieren
If ($CheckRegistry = True) Then
    MsgBox(64, $ScriptName, "Office 2010 Installation entdeck, wird nun deinstalliert", 3)
    RunWait($Server & "Programme\Installation\Office2010SP1\x86\setup.exe /uninstall ProPlus /config \\xxx\Programme\Installation\Office2010SP1\x86\ProPlus.WW\uninstall.xml")
    MsgBox(64, $ScriptName, "Office 2010 wurde deinstalliert", 3)
EndIf



; Office 2013 Installation überprüfen
$string = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{90150000-0011-0000-0000-0000000FF1CE}", "DisplayName")
$pos = StringInStr($string, "Microsoft Office")
If ($pos = 1) Then
    $CheckRegistry = True
Else
    $CheckRegistry = False
EndIf

; Office 2013 deinstallieren
If ($CheckRegistry = True) Then
    MsgBox(64, $ScriptName, "Office 2013 Installation entdeck, wird nun deinstalliert", 3)
    $success = RunWait($Server & "Programme\Installation\Office2013SP1\x86\setup.exe /uninstall ProPlus /config \\xxx\Programme\Installation\Office2013SP1\x86\ProPlus.WW\uninstall.xml")

    If($success <> 0) Then
        MsgBox(64, $ScriptName, "Office 2013 wurde erfolgreich deinstalliert", 3)
    Else
        MsgBox(64, $ScriptName, "Office 2013 wurde nicht deinstalliert.", 3)
        Exit(1)
    EndIf
EndIf





; Office 2016 Installation starten
$Setup = $Server & $ProgrammPfad & $ProgrammDatei

If FileExists($Setup) Then

    $success = RunWait($Setup & $Parameter)
    If ($success <> 0) Then
        MsgBox (16, $ScriptName, "Die Installation von Office 2016 ist fehlgeschalgen.")
        $hEventLog = _EventLog__Open("", $ScriptName)
        _EventLog__Report($hEventLog, 1, 0, 2, "Administrator", "Die Installation von Office 2016 ist fehlgeschalgen. Fehlercode: " & $success, $aData)
        _EventLog__Close($hEventLog)
        Exit(1)
    Else
        MsgBox (16, $ScriptName, "Die Installation von Office 2016 war erfolgreich")
        ; Eintrag im Eventlog nach der Installation
        $hEventLog = _EventLog__Open("", $ScriptName)
        _EventLog__Report($hEventLog, 0, 0, 2, "Administrator", "Die Installation von Office 2016 war erfolgreich", $aData)
        _EventLog__Close($hEventLog)
    EndIf

Else
    MsgBox (16, $ScriptName, "Die Datei " & $Setup & " wurde nicht gefunden.")
    $hEventLog = _EventLog__Open("", $ScriptName)
    _EventLog__Report($hEventLog, 1, 0, 2, "Administrator", "Die Installationsdatei wurde nicht gefunden", $aData)
    _EventLog__Close($hEventLog)
    Exit(1)

EndIf



; Meldung nach der Programminstallation
TrayTip($ScriptName & " installiert", "Die Installation wurde abgeschlossen", 10)
Sleep(2000)

Exit(0)

Okay, here is the code from the script.

In the first part, reading some network config from an ini file and define the correct server.

Later checking for some previous office installations (2010 & 2013) in the registry and after that installalling the office 2016 version

I have not declared any variables, this was never neccessary for this kind of installations scripts I use since years, have there been some changes in autoit, so it is now required?

Do I have to change my scripts in future to avoid these errors?

Edited by blumi

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

I think it is best to declare variables to avoid the error arising.
 

#RequireAdmin
Opt("MustDeclareVars", 1)
Opt("TrayAutoPause", 0)
#Region
#AutoIt3Wrapper_Icon=\\xxx\Administration\AutoIt\Icons\Office 2013.ico
#AutoIt3Wrapper_Outfile=\\xxx\Administration\AutoIt\Installationsscripte\Office 2016 x86.exe
#AutoIt3Wrapper_Res_Fileversion=1.0.0.9
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
#AutoIt3Wrapper_Res_Language=1031
#EndRegion 
;#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7
;
; Programm:                 Office 2016 x86
; Datum:                        18.11.2015
; AutoIt3 Version:  3.3.14.1
;

;#include <file.au3>
;#include <array.au3>
;#include <EventLog.au3>

Global Const $STR_REGEXPARRAYMATCH = 1
Global Const $tagRECT = "struct;long Left;long Top;long Right;long Bottom;endstruct"
Global Const $KF_EXTENDED = 0x0100
Global Const $KF_ALTDOWN = 0x2000
Global Const $KF_UP = 0x8000
Global $__g_sSourceName_Event

Global $ScriptName = "Office 2016 x86"
Global $ProgrammPfad = "Programme\Installation\Office2016\x86\"
Global $ProgrammDatei = "setup.exe"
Global $Parameter = " /adminfile Office2016.MSP"
Global $ConfigPfad = "\Administration\AutoIt\"
Global $ConfigFile = "config.ini"
;Global $config,$SplitPath,$SplitServer,$aArray,$counter,$standort,$server,$string,$pos,$CheckRegistry,$success,$Setup
Local $hEventLog, $aData[4] = [3, 1, 2, 3]
Local $config,$SplitPath,$SplitServer
If (FileExists(@ScriptDir & "\" & $ConfigFile)) Then
    $config = @ScriptDir & "\" & $ConfigFile
Else
    Dim $SplitDrive, $SplitDir, $SplitFileName, $SplitExtension
    $SplitPath = _PathSplit(@ScriptFullPath, $SplitDrive, $SplitDir, $SplitFileName, $SplitExtension)
    $SplitServer = $SplitPath[1]
    $config = $SplitServer & $ConfigPfad & $ConfigFile
EndIf
Local $aArray,$counter,$standort,$server
If (FileExists($config)) Then
    $aArray = IniReadSection($config, "IP")
    $counter = $aArray[0][0]
    For $i = 1 To $counter
        If (StringInStr(@IPAddress1, $aArray[$i][1])) Or (StringInStr(@IPAddress2, $aArray[$i][1])) Then
            $standort = $aArray[$i][0]
            $server = IniRead($config, "Server", $standort, "Fehler")
        EndIf
    Next
    $server = "\\" & $server & "\"
Else
    MsgBox(16, $ScriptName, "Die Konfigurationsdatei " & $config & " wurde nicht gefunden.")
    $hEventLog = _EventLog__Open("", $ScriptName)
    _EventLog__Report($hEventLog, 1, 0, 2, "Administrator", "Die Konfigurationsdatei wurde nicht gefunden", $aData)
    _EventLog__Close($hEventLog)
    Exit (1)
EndIf
TrayTip($ScriptName & " - Installation", $ScriptName & " wird installiert. Bitte warten...", 2000)
Local $string = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{7CDE44B1-0759-483A-924C-CB65DF98F5F8}", "DisplayName")
Local $pos = StringInStr($string, "Clientkomponenten")
Local $CheckRegistry=False
If ($pos = 1) Then
    $CheckRegistry = True
Else
    $CheckRegistry = False
EndIf
If ($CheckRegistry = True) Then
    MsgBox(64, $ScriptName, "Clientkomponenten für Outlook entdeck, wird nun deinstalliert", 3)
    RunWait('msiexec /qb- /x {7CDE44B1-0759-483A-924C-CB65DF98F5F8} /norestart')
    MsgBox(64, $ScriptName, "Clientkomponenten für Outlook wurden deinstalliert", 3)
EndIf
$string = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{90140000-0011-0000-0000-0000000FF1CE}", "DisplayName")
$pos = StringInStr($string, "Microsoft Office")
If ($pos = 1) Then
    $CheckRegistry = True
Else
    $CheckRegistry = False
EndIf
If ($CheckRegistry = True) Then
    MsgBox(64, $ScriptName, "Office 2010 Installation entdeck, wird nun deinstalliert", 3)
    RunWait($server & "Programme\Installation\Office2010SP1\x86\setup.exe /uninstall ProPlus /config \\xxx\Programme\Installation\Office2010SP1\x86\ProPlus.WW\uninstall.xml")
    MsgBox(64, $ScriptName, "Office 2010 wurde deinstalliert", 3)
EndIf
$string = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{90150000-0011-0000-0000-0000000FF1CE}", "DisplayName")
$pos = StringInStr($string, "Microsoft Office")
If ($pos = 1) Then
    $CheckRegistry = True
Else
    $CheckRegistry = False
EndIf
Local $success
If ($CheckRegistry = True) Then
    MsgBox(64, $ScriptName, "Office 2013 Installation entdeck, wird nun deinstalliert", 3)
    $success = RunWait($server & "Programme\Installation\Office2013SP1\x86\setup.exe /uninstall ProPlus /config \\xxx\Programme\Installation\Office2013SP1\x86\ProPlus.WW\uninstall.xml")
    If ($success <> 0) Then
        MsgBox(64, $ScriptName, "Office 2013 wurde erfolgreich deinstalliert", 3)
    Else
        MsgBox(64, $ScriptName, "Office 2013 wurde nicht deinstalliert.", 3)
        Exit (1)
    EndIf
EndIf
Local $Setup = $server & $ProgrammPfad & $ProgrammDatei
If FileExists($Setup) Then
    $success = RunWait($Setup & $Parameter)
    If ($success <> 0) Then
        MsgBox(16, $ScriptName, "Die Installation von Office 2016 ist fehlgeschalgen.")
        $hEventLog = _EventLog__Open("", $ScriptName)
        _EventLog__Report($hEventLog, 1, 0, 2, "Administrator", "Die Installation von Office 2016 ist fehlgeschalgen. Fehlercode: " & $success, $aData)
        _EventLog__Close($hEventLog)
        Exit (1)
    Else
        MsgBox(16, $ScriptName, "Die Installation von Office 2016 war erfolgreich")
        $hEventLog = _EventLog__Open("", $ScriptName)
        _EventLog__Report($hEventLog, 0, 0, 2, "Administrator", "Die Installation von Office 2016 war erfolgreich", $aData)
        _EventLog__Close($hEventLog)
    EndIf
Else
    MsgBox(16, $ScriptName, "Die Datei " & $Setup & " wurde nicht gefunden.")
    $hEventLog = _EventLog__Open("", $ScriptName)
    _EventLog__Report($hEventLog, 1, 0, 2, "Administrator", "Die Installationsdatei wurde nicht gefunden", $aData)
    _EventLog__Close($hEventLog)
    Exit (1)
EndIf
TrayTip($ScriptName & " installiert", "Die Installation wurde abgeschlossen", 10)
Sleep(2000)
Exit (0)


Func _EventLog__Close($hEventLog)
    Local $aResult = DllCall("advapi32.dll", "bool", "CloseEventLog", "handle", $hEventLog)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] <> 0
EndFunc   ;==>_EventLog__Close
Func _EventLog__Open($sServerName, $sSourceName)
    $__g_sSourceName_Event = $sSourceName
    Local $aResult = DllCall("advapi32.dll", "handle", "OpenEventLogW", "wstr", $sServerName, "wstr", $sSourceName)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[0]
EndFunc   ;==>_EventLog__Open
Func _EventLog__Report($hEventLog, $iType, $iCategory, $iEventID, $sUserName, $sDesc, $aData)
    Local $tSID = 0
    If $sUserName <> "" Then
        $tSID = _Security__GetAccountSid($sUserName)
    EndIf
    Local $iData = $aData[0]
    Local $tData = DllStructCreate("byte[" & $iData & "]")
    Local $iDesc = StringLen($sDesc) + 1
    Local $tDesc = DllStructCreate("wchar[" & $iDesc & "]")
    Local $tPtr = DllStructCreate("ptr")
    DllStructSetData($tPtr, 1, DllStructGetPtr($tDesc))
    DllStructSetData($tDesc, 1, $sDesc)
    For $iI = 1 To $iData
        DllStructSetData($tData, 1, $aData[$iI], $iI)
    Next
    Local $aResult = DllCall("advapi32.dll", "bool", "ReportEventW", "handle", $hEventLog, "word", $iType, "word", $iCategory, "dword", $iEventID, "struct*", $tSID, "word", 1, "dword", $iData, "struct*", $tPtr, "struct*", $tData)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] <> 0
EndFunc   ;==>_EventLog__Report
Func _PathSplit($sFilePath, ByRef $sDrive, ByRef $sDir, ByRef $sFileName, ByRef $sExtension)
    Local $aArray = StringRegExp($sFilePath, "^\h*((?:\\\\\?\\)*(\\\\[^\?\/\\]+|[A-Za-z]:)?(.*[\/\\]\h*)?((?:[^\.\/\\]|(?(?=\.[^\/\\]*\.)\.))*)?([^\/\\]*))$", $STR_REGEXPARRAYMATCH)
    If @error Then
        ReDim $aArray[5]
        $aArray[0] = $sFilePath
    EndIf
    $sDrive = $aArray[1]
    If StringLeft($aArray[2], 1) == "/" Then
        $sDir = StringRegExpReplace($aArray[2], "\h*[\/\\]+\h*", "\/")
    Else
        $sDir = StringRegExpReplace($aArray[2], "\h*[\/\\]+\h*", "\\")
    EndIf
    $aArray[2] = $sDir
    $sFileName = $aArray[3]
    $sExtension = $aArray[4]
    Return $aArray
EndFunc   ;==>_PathSplit
Func _Security__GetAccountSid($sAccount, $sSystem = "")
    Local $aAcct = _Security__LookupAccountName($sAccount, $sSystem)
    If @error Then Return SetError(@error, @extended, 0)
    If IsArray($aAcct) Then Return _Security__StringSidToSid($aAcct[0])
    Return ''
EndFunc   ;==>_Security__GetAccountSid
Func _Security__GetLengthSid($pSID)
    If Not _Security__IsValidSid($pSID) Then Return SetError(@error + 10, @extended, 0)
    Local $aCall = DllCall("advapi32.dll", "dword", "GetLengthSid", "struct*", $pSID)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aCall[0]
EndFunc   ;==>_Security__GetLengthSid
Func _Security__IsValidSid($pSID)
    Local $aCall = DllCall("advapi32.dll", "bool", "IsValidSid", "struct*", $pSID)
    If @error Then Return SetError(@error, @extended, False)
    Return Not ($aCall[0] = 0)
EndFunc   ;==>_Security__IsValidSid
Func _Security__LookupAccountName($sAccount, $sSystem = "")
    Local $tData = DllStructCreate("byte SID[256]")
    Local $aCall = DllCall("advapi32.dll", "bool", "LookupAccountNameW", "wstr", $sSystem, "wstr", $sAccount, "struct*", $tData, "dword*", DllStructGetSize($tData), "wstr", "", "dword*", DllStructGetSize($tData), "int*", 0)
    If @error Or Not $aCall[0] Then Return SetError(@error, @extended, 0)
    Local $aAcct[3]
    $aAcct[0] = _Security__SidToStringSid(DllStructGetPtr($tData, "SID"))
    $aAcct[1] = $aCall[5]
    $aAcct[2] = $aCall[7]
    Return $aAcct
EndFunc   ;==>_Security__LookupAccountName
Func _Security__SidToStringSid($pSID)
    If Not _Security__IsValidSid($pSID) Then Return SetError(@error + 10, 0, "")
    Local $aCall = DllCall("advapi32.dll", "bool", "ConvertSidToStringSidW", "struct*", $pSID, "ptr*", 0)
    If @error Or Not $aCall[0] Then Return SetError(@error, @extended, "")
    Local $pStringSid = $aCall[2]
    Local $aLen = DllCall("kernel32.dll", "int", "lstrlenW", "struct*", $pStringSid)
    Local $sSID = DllStructGetData(DllStructCreate("wchar Text[" & $aLen[0] + 1 & "]", $pStringSid), "Text")
    DllCall("kernel32.dll", "handle", "LocalFree", "handle", $pStringSid)
    Return $sSID
EndFunc   ;==>_Security__SidToStringSid
Func _Security__StringSidToSid($sSID)
    Local $aCall = DllCall("advapi32.dll", "bool", "ConvertStringSidToSidW", "wstr", $sSID, "ptr*", 0)
    If @error Or Not $aCall[0] Then Return SetError(@error, @extended, 0)
    Local $pSID = $aCall[2]
    Local $tBuffer = DllStructCreate("byte Data[" & _Security__GetLengthSid($pSID) & "]", $pSID)
    Local $tSID = DllStructCreate("byte Data[" & DllStructGetSize($tBuffer) & "]")
    DllStructSetData($tSID, "Data", DllStructGetData($tBuffer, "Data"))
    DllCall("kernel32.dll", "handle", "LocalFree", "handle", $pSID)
    Return $tSID
EndFunc   ;==>_Security__StringSidToSid

 

Edited by Trong
grammar

Regards,
 

Share this post


Link to post
Share on other sites

Er...I wouldn't follow you, because that's displaying an awful set of best practices there. Why do you inline UDF functions like that and then post to the Forum telling the OP that's the way to do it?


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Long story short: You are not always defining $Server used in line 119 when this test fails:

If (FileExists($config)) Then

So make it a habit to declare all Globally used variables.

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

@guinness:
Over time the file "Include" will change.
Next person to may have trouble with script-breaking changes.


Regards,
 

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

@guinness:
Over time the file "Include" will change.
Next person to may have trouble with script-breaking changes.

Changes normally being bug fixes? So you would rather deploy buggy code to production all for the sake of not spending 1 minute looking at the changelog of a release? Even on a Forum level, the code you have posted above is outdated, as I have fixed something wrong with _PathSplit(). So I am not asking you, I am telling you, do not strip include functions and post on the Forum, because it's not helping anyone for the future. If you don't agree, then may I suggest you think how would you feel if you copied code from the Forum that was already outdated?

Edited by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

[...] So I am not asking you, I am telling you, do not strip include functions and post on the Forum, because it's not helping anyone for the future. If you don't agree, then may I suggest you think how would you feel if you copied code from the Forum that was already outdated?

 

I do not think more than a million posts on and the example script or UDF on this forum is always updated.

I met many difficulties in reusing the example script or old UDF, if unfortunately could link is dead.
I do not think that myself to write up everything as fast.
Otherwise I was disconnected from the network and read help file: D

After all I will follow the you, I will not strip include functions and post on the Forum again.
Thank you for your suggestion.


Regards,
 

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

Forget it. AutoItSetOption("MustDeclareVars", 1) was already set.

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Not sure if serious.

Although the way it's stated is little harsh, I agree with the principal statement not to copy Func from UDF libraries into posted code but use the #include.

Jos 

1 person likes this

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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