Sign in to follow this  
Followers 0
Docfxit

Error running compiled script

5 posts in this topic

#1 ·  Posted (edited)

When I run a compiled script I get this error:
autoiterror.jpg
 
As you can see there aren't that many line numbers in the script below.
 
This is the script I compiled:

]
#include <WinAPI.au3>
AutoItSetOption("TrayIconDebug", 1) ;0-off
; Set so that tray displays current line number

Global $iError = 0, $iExtended = 0
Global $tText = DllStructCreate("char Text[4096]")
Global $pText = DllStructGetPtr($tText), $sMessage = "<None>"
;Local Const $FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000   ;[color=#ff0000]I removed this line it is the error[/color]
DriveMapGet("L:")
If @error = 1 Then
    DriveMapAdd("L:", "\\ATU1277\Scans", 0, "ATU1277\SCANS", "Password"); Local account on remote computer
    _CheckError(@error, @extended)
EndIf
$Line1 = $CMDLINE[1]
$CMDLINE[1] & @CRLF & "Passed Paramater 2 = " & $CMDLINE[2])
$CMDLINE[1])

; View a document...
If $CMDLINE[1] = "V"  Then
    Run("C:\PROGRA~1\IRFANVIEW\I_VIEW32" & " " & "L:\" & $CMDLINE[2])
Else
    ; Scan a document
    If $CMDLINE[1] = "S"  Then
        Run("C:\PROGRA~1\IRFANVIEW\I_VIEW32" & " /scan /convert=" & "L:\" & $CMDLINE[2])
    Else
        MsgBox(0x40000, 'CMDLINE  Error', "Error" & @CRLF & "Passed Paramater 0 = " & $CMDLINE[0] & @CRLF & "Passed Paramater 1 = " & $CMDLINE[1] & @CRLF & "Passed Paramater 2 = " & $CMDLINE[2])

    EndIf
EndIf
Exit

Func _CheckError($iError, $iExtended = '')
    If $iError <> 0 Then
        Switch $iError
            Case 1
                _WinAPI_FormatMessage($FORMAT_MESSAGE_FROM_SYSTEM, 0, $iExtended, 0, $pText, 4096, 0)
                $sMessage = DllStructGetData($tText, "Text")
                MsgBox(0, "Error Mapping Drive", "@error = " & $iError & @CRLF & _
                        "@iExtended = " & @iExtended & @CRLF & _
                        "Message = " & $sMessage)
            Case 2
                MsgBox(16, "ERROR", "Access to the remote share was denied.")
            Case 3
                MsgBox(64, "WARNING", "The device is already assigned.")
            Case 4
                MsgBox(16, "ERROR", "Invalid device name.")
            Case 5
                MsgBox(16, "ERROR", "Invalid remote share.")
            Case 6
                MsgBox(16, "ERROR", "Invalid password.")
        EndSwitch
    EndIf
EndFunc   ;==>_CheckError

 
I'm compiling it with AudIt ver. 3.3.10.2
 
What can I do to correct:
1. The line number?
2. The error?
 
Thank you,
 
Docfxit

Edited by Docfxit
Fixed tags

Share this post


Link to post
Share on other sites

It's [/autoit] not [autoit]


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

the obvious thing to do is to run your script uncompiled, so SciTe will show you exactly what is wrong where.

the line count includes all #include files, so no wonder it exceeds your expectations.

the error says what it says: you can not redeclare a constant. if you expect you could redeclare a constant, then that wouldn't make it a constant, would it? the only const in your script is in line:

Local Const $FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000

it is probably already declared in the WinAPI include. comment-out this line and check again.

Edited by orbs

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

it is probably already declared in the WinAPI include. comment-out this line and check again.

That's great.  It didn't occur to me that it might be in an include.  I commented it out and that solved the problem

Thank you very much,

Docfxit

Edited by Docfxit

Share this post


Link to post
Share on other sites

When I run this script I'm getting an error mapping the drive. 

AutoItError2.jpg

I though it might be nice to get a more user friendly error window (maybe explaining what the errors are in English)

So I tried adding an error handler created by  jennico called _ErrorHandler.au3 at: '?do=embed' frameborder='0' data-embedContent>>

When I did I am now getting an error saying:

"Skipping AU3check: Current version doesn't support the AutoIt3 v 3.3.9.5+ syntax."

and I'm getting:

"C:\Program Files\AutoIt3\Include\Memory.au3" (65) : ==> "Func" statement has no matching "EndFunc".:
Func _MemFree(ByRef $tMemMap)

I don't understand why I'm getting the second error.  I looked at the AutoIt supplied Memory.au3 script and it does have an EndFunc.

#include-once

#include "MemoryConstants.au3"
#include "StructureConstants.au3"
#include "ProcessConstants.au3"
#include "Security.au3"

; #INDEX# =======================================================================================================================
; Title .........: Memory
; AutoIt Version : 3.3.7.20++
; Description ...: Functions that assist with Memory management.
;                  The memory manager implements virtual memory, provides a core set of services such  as  memory  mapped  files,
;                  copy-on-write memory, large memory support, and underlying support for the cache manager.
; Author(s) .....: Paul Campbell (PaulIA)
; Dll(s) ........: kernel32.dll
; ===============================================================================================================================

; #CURRENT# =====================================================================================================================
; _MemGlobalAlloc
; _MemGlobalFree
; _MemGlobalLock
; _MemGlobalSize
; _MemGlobalUnlock
; _MemMoveMemory
; _MemVirtualAlloc
; _MemVirtualAllocEx
; _MemVirtualFree
; _MemVirtualFreeEx
; ===============================================================================================================================

; #INTERNAL_USE_ONLY# ===========================================================================================================
; $tagMEMMAP
; _MemFree
; _MemInit
; _MemRead
; _MemWrite
; __Mem_OpenProcess
; ===============================================================================================================================

; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name...........: $tagMEMMAP
; Description ...: Contains information about the memory
; Fields ........: hProc - Handle to the external process
;                  Size  - Size, in bytes, of the memory block allocated
;                  Mem   - Pointer to the memory block
; Author ........: Paul Campbell (PaulIA)
; Remarks .......:
; ===============================================================================================================================
Global Const $tagMEMMAP = "handle hProc;ulong_ptr Size;ptr Mem"

; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name...........: _MemFree
; Description ...: Releases a memory map structure for a control
; Syntax.........: _MemFree ( ByRef $tMemMap )
; Parameters ....: $tMemMap     - tagMEMMAP structure
; Return values .: Success      - True
;                  Failure      - False
; Author ........: Paul Campbell (PaulIA)
; Modified.......:
; Remarks .......: This function is used internally by Auto3Lib and should not normally be called
; Related .......: _MemInit
; Link ..........:
; Example .......:
; ===============================================================================================================================
Func _MemFree(ByRef $tMemMap)
    Local $pMemory = DllStructGetData($tMemMap, "Mem")
    Local $hProcess = DllStructGetData($tMemMap, "hProc")
    Local $bResult = _MemVirtualFreeEx($hProcess, $pMemory, 0, $MEM_RELEASE)
    DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $hProcess)
    If @error Then Return SetError(@error, @extended, False)
    Return $bResult
EndFunc   ;==>_MemFree

; #FUNCTION# ====================================================================================================================
; Author ........: Paul Campbell (PaulIA)
; Modified.......:
; ===============================================================================================================================
Func _MemGlobalAlloc($iBytes, $iFlags = 0)
    Local $aResult = DllCall("kernel32.dll", "handle", "GlobalAlloc", "uint", $iFlags, "ulong_ptr", $iBytes)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[0]
EndFunc   ;==>_MemGlobalAlloc

; #FUNCTION# ====================================================================================================================
; Author ........: Paul Campbell (PaulIA)
; Modified.......:
; ===============================================================================================================================
Func _MemGlobalFree($hMem)
    Local $aResult = DllCall("kernel32.dll", "ptr", "GlobalFree", "handle", $hMem)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0]
EndFunc   ;==>_MemGlobalFree

; #FUNCTION# ====================================================================================================================
; Author ........: Paul Campbell (PaulIA)
; Modified.......:
; ===============================================================================================================================
Func _MemGlobalLock($hMem)
    Local $aResult = DllCall("kernel32.dll", "ptr", "GlobalLock", "handle", $hMem)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[0]
EndFunc   ;==>_MemGlobalLock

; #FUNCTION# ====================================================================================================================
; Author ........: Paul Campbell (PaulIA)
; Modified.......:
; ===============================================================================================================================
Func _MemGlobalSize($hMem)
    Local $aResult = DllCall("kernel32.dll", "ulong_ptr", "GlobalSize", "handle", $hMem)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[0]
EndFunc   ;==>_MemGlobalSize

; #FUNCTION# ====================================================================================================================
; Author ........: Paul Campbell (PaulIA)
; Modified.......:
; ===============================================================================================================================
Func _MemGlobalUnlock($hMem)
    Local $aResult = DllCall("kernel32.dll", "bool", "GlobalUnlock", "handle", $hMem)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[0]
EndFunc   ;==>_MemGlobalUnlock

; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name...........: _MemInit
; Description ...: Initializes a tagMEMMAP structure for a control
; Syntax.........: _MemInit ( $hWnd, $iSize, ByRef $tMemMap )
; Parameters ....: $hWnd        - Window handle of the process where memory will be mapped
;                  $iSize       - Size, in bytes, of memory space to map
;                  $tMemMap     - tagMEMMAP structure that will be initialized
; Return values .: Success      - Pointer to reserved memory block
;                  Failure      - 0
; Author ........: Paul Campbell (PaulIA)
; Modified.......:
; Remarks .......: This function is used internally by Auto3Lib and should not normally be called
; Related .......: _MemFree
; Link ..........:
; Example .......:
; ===============================================================================================================================
Func _MemInit($hWnd, $iSize, ByRef $tMemMap)
    Local $aResult = DllCall("User32.dll", "dword", "GetWindowThreadProcessId", "hwnd", $hWnd, "dword*", 0)
    If @error Then Return SetError(@error + 10, @extended, 0)
    Local $iProcessID = $aResult[2]
    If $iProcessID = 0 Then Return SetError(1, 0, 0) ; Invalid window handle

    Local $iAccess = BitOR($PROCESS_VM_OPERATION, $PROCESS_VM_READ, $PROCESS_VM_WRITE)
    Local $hProcess = __Mem_OpenProcess($iAccess, False, $iProcessID, True)
    Local $iAlloc = BitOR($MEM_RESERVE, $MEM_COMMIT)
    Local $pMemory = _MemVirtualAllocEx($hProcess, 0, $iSize, $iAlloc, $PAGE_READWRITE)

    If $pMemory = 0 Then Return SetError(2, 0, 0) ; Unable to allocate memory

    $tMemMap = DllStructCreate($tagMEMMAP)
    DllStructSetData($tMemMap, "hProc", $hProcess)
    DllStructSetData($tMemMap, "Size", $iSize)
    DllStructSetData($tMemMap, "Mem", $pMemory)
    Return $pMemory
EndFunc   ;==>_MemInit

; #FUNCTION# ====================================================================================================================
; Author ........: Paul Campbell (PaulIA)
; Modified.......:
; ===============================================================================================================================
Func _MemMoveMemory($pSource, $pDest, $iLength)
    DllCall("kernel32.dll", "none", "RtlMoveMemory", "struct*", $pDest, "struct*", $pSource, "ulong_ptr", $iLength)
    If @error Then Return SetError(@error, @extended)
EndFunc   ;==>_MemMoveMemory

; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name...........: _MemRead
; Description ...: Transfer memory from external address space to internal address space
; Syntax.........: _MemRead ( ByRef $tMemMap, $pSrce, $pDest, $iSize )
; Parameters ....: $tMemMap     - tagMEMMAP structure
;                  $pSrce       - Pointer to external memory
;                  $pDest       - Pointer to internal memory
;                  $iSize       - Size in bytes of memory to read
; Return values .: Success      - True
;                  Failure      - False
; Author ........: Paul Campbell (PaulIA)
; Modified.......:
; Remarks .......: This function is used internally by Auto3Lib and should not normally be called
; Related .......: _MemWrite
; Link ..........:
; Example .......:
; ===============================================================================================================================
Func _MemRead(ByRef $tMemMap, $pSrce, $pDest, $iSize)
    Local $aResult = DllCall("kernel32.dll", "bool", "ReadProcessMemory", "handle", DllStructGetData($tMemMap, "hProc"), _
            "ptr", $pSrce, "struct*", $pDest, "ulong_ptr", $iSize, "ulong_ptr*", 0)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0]
EndFunc   ;==>_MemRead

; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name...........: _MemWrite
; Description ...: Transfer memory to external address space from internal address space
; Syntax.........: _MemWrite ( ByRef $tMemMap, $pSrce [, $pDest = 0 [, $iSize = 0 [, $sSrce = "ptr"]]] )
; Parameters ....: $tMemMap     - tagMEMMAP structure
;                  $pSrce       - Pointer to internal memory
;                  $pDest       - Pointer to external memory
;                  $iSize       - Size in bytes of memory to write
;                  $sSrce       - Contains the data type for $pSrce
; Return values .: Success      - True
;                  Failure      - False
; Author ........: Paul Campbell (PaulIA)
; Modified.......:
; Remarks .......: This function is used internally by Auto3Lib and should not normally be called
; Related .......: _MemRead
; Link ..........:
; Example .......:
; ===============================================================================================================================
Func _MemWrite(ByRef $tMemMap, $pSrce, $pDest = 0, $iSize = 0, $sSrce = "struct*")
    If $pDest = 0 Then $pDest = DllStructGetData($tMemMap, "Mem")
    If $iSize = 0 Then $iSize = DllStructGetData($tMemMap, "Size")
    Local $aResult = DllCall("kernel32.dll", "bool", "WriteProcessMemory", "handle", DllStructGetData($tMemMap, "hProc"), _
            "ptr", $pDest, $sSrce, $pSrce, "ulong_ptr", $iSize, "ulong_ptr*", 0)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0]
EndFunc   ;==>_MemWrite

; #FUNCTION# ====================================================================================================================
; Author ........: Paul Campbell (PaulIA)
; Modified.......:
; ===============================================================================================================================
Func _MemVirtualAlloc($pAddress, $iSize, $iAllocation, $iProtect)
    Local $aResult = DllCall("kernel32.dll", "ptr", "VirtualAlloc", "ptr", $pAddress, "ulong_ptr", $iSize, "dword", $iAllocation, "dword", $iProtect)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[0]
EndFunc   ;==>_MemVirtualAlloc

; #FUNCTION# ====================================================================================================================
; Author ........: Paul Campbell (PaulIA)
; Modified.......:
; ===============================================================================================================================
Func _MemVirtualAllocEx($hProcess, $pAddress, $iSize, $iAllocation, $iProtect)
    Local $aResult = DllCall("kernel32.dll", "ptr", "VirtualAllocEx", "handle", $hProcess, "ptr", $pAddress, "ulong_ptr", $iSize, "dword", $iAllocation, "dword", $iProtect)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[0]
EndFunc   ;==>_MemVirtualAllocEx

; #FUNCTION# ====================================================================================================================
; Author ........: Paul Campbell (PaulIA)
; Modified.......:
; ===============================================================================================================================
Func _MemVirtualFree($pAddress, $iSize, $iFreeType)
    Local $aResult = DllCall("kernel32.dll", "bool", "VirtualFree", "ptr", $pAddress, "ulong_ptr", $iSize, "dword", $iFreeType)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0]
EndFunc   ;==>_MemVirtualFree

; #FUNCTION# ====================================================================================================================
; Author ........: Paul Campbell (PaulIA)
; Modified.......:
; ===============================================================================================================================
Func _MemVirtualFreeEx($hProcess, $pAddress, $iSize, $iFreeType)
    Local $aResult = DllCall("kernel32.dll", "bool", "VirtualFreeEx", "handle", $hProcess, "ptr", $pAddress, "ulong_ptr", $iSize, "dword", $iFreeType)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0]
EndFunc   ;==>_MemVirtualFreeEx

; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name...........: __Mem_OpenProcess
; Description ...: Returns a handle of an existing process object
; Syntax.........: _WinAPI_OpenProcess ( $iAccess, $fInherit, $iProcessID [, $fDebugPriv = False] )
; Parameters ....: $iAccess     - Specifies the access to the process object
;                  $fInherit    - Specifies whether the returned handle can be inherited
;                  $iProcessID  - Specifies the process identifier of the process to open
;                  $fDebugPriv  - Certain system processes can not be opened unless you have the  debug  security  privilege.  If
;                  +True, this function will attempt to open the process with debug priviliges if the process can not  be  opened
;                  +with standard access privileges.
; Return values .: Success      - Process handle to the object
; Author ........: Paul Campbell (PaulIA)
; Modified.......: jpm
; Remarks .......:
; Related .......:
; Link ..........: @@MsdnLink@@ OpenProcess
; Example .......:
; ===============================================================================================================================
Func __Mem_OpenProcess($iAccess, $fInherit, $iProcessID, $fDebugPriv = False)
    ; Attempt to open process with standard security priviliges
    Local $aResult = DllCall("kernel32.dll", "handle", "OpenProcess", "dword", $iAccess, "bool", $fInherit, "dword", $iProcessID)
    If @error Then Return SetError(@error + 10, @extended, 0)
    If $aResult[0] Then Return $aResult[0]
    If Not $fDebugPriv Then Return 0

    ; Enable debug privileged mode
    Local $hToken = _Security__OpenThreadTokenEx(BitOR($TOKEN_ADJUST_PRIVILEGES, $TOKEN_QUERY))
    If @error Then Return SetError(@error + 20, @extended, 0)
    _Security__SetPrivilege($hToken, "SeDebugPrivilege", True)
    Local $iError = @error
    Local $iLastError = @extended
    Local $iRet = 0
    If Not @error Then
        ; Attempt to open process with debug privileges
        $aResult = DllCall("kernel32.dll", "handle", "OpenProcess", "dword", $iAccess, "bool", $fInherit, "dword", $iProcessID)
        $iError = @error
        $iLastError = @extended
        If $aResult[0] Then $iRet = $aResult[0]

        ; Disable debug privileged mode
        _Security__SetPrivilege($hToken, "SeDebugPrivilege", False)
        If @error Then
            $iError = @error + 30
            $iLastError = @extended
        EndIf
    Else
        $iError = @error + 40
    EndIf
    DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $hToken)
    ; No need to test @error.

    Return SetError($iError, $iLastError, $iRet)
EndFunc   ;==>__Mem_OpenProcess

 

The above script is supplied with AutoIt ver. 3.3.10.2

Thank you,

Docfxit

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
Sign in to follow this  
Followers 0