Jump to content
Sign in to follow this  
MrKris1224

Getting process parent ID crash script

Recommended Posts

MrKris1224

Hi, I have a very big problem. I did find some code for getting parent PID on this forum. But I have big problem with that code. Sometimes if i running my script i get error "AutoIt Error - Unable to open the script file"... If I compile it again then script works again and sometime ago again i have that error. It's this funtion:
 

Func _GetParentPID($i_pid)
    Local Const $TH32CS_SNAPPROCESS = 0x00000002

    Local $a_tool_help = DllCall("Kernel32.dll", "long", "CreateToolhelp32Snapshot", "int", $TH32CS_SNAPPROCESS, "int", 0)
    If IsArray($a_tool_help) = 0 Or $a_tool_help[0] = -1 Then Return SetError(1, 0, $i_pid)

    Local $tagPROCESSENTRY32 = _
        DllStructCreate _
            ( _
                "dword dwsize;" & _
                "dword cntUsage;" & _
                "dword th32ProcessID;" & _
                "uint th32DefaultHeapID;" & _
                "dword th32ModuleID;" & _
                "dword cntThreads;" & _
                "dword th32ParentProcessID;" & _
                "long pcPriClassBase;" & _
                "dword dwFlags;" & _
                "char szExeFile[260]" _
            )
    DllStructSetData($tagPROCESSENTRY32, 1, DllStructGetSize($tagPROCESSENTRY32))

    Local $p_PROCESSENTRY32 = DllStructGetPtr($tagPROCESSENTRY32)

    Local $a_pfirst = DllCall("Kernel32.dll", "int", "Process32First", "long", $a_tool_help[0], "ptr", $p_PROCESSENTRY32)
    If IsArray($a_pfirst) = 0 Then Return SetError(2, 0, $i_pid)

    Local $a_pnext, $i_return = 0
    If DllStructGetData($tagPROCESSENTRY32, "th32ProcessID") = $i_pid Then
        $i_return = DllStructGetData($tagPROCESSENTRY32, "th32ParentProcessID")
        DllCall("Kernel32.dll", "int", "CloseHandle", "long", $a_tool_help[0])
        If $i_return Then Return $i_return
        Return $i_pid
    EndIf

    While 1
        $a_pnext = DLLCall("Kernel32.dll", "int", "Process32Next", "long", $a_tool_help[0], "ptr", $p_PROCESSENTRY32)
        If IsArray($a_pnext) And $a_pnext[0] = 0 Then ExitLoop
        If DllStructGetData($tagPROCESSENTRY32, "th32ProcessID") = $i_pid Then
            $i_return = DllStructGetData($tagPROCESSENTRY32, "th32ParentProcessID")
            If $i_return Then ExitLoop
            $i_return = $i_pid
            ExitLoop
        EndIf
    WEnd

    If $i_return = "" Then $i_return = $i_pid

    DllCall("Kernel32.dll", "int", "CloseHandle", "long", $a_tool_help[0])
    Return $i_return
EndFunc

Anybody can help me with it and say what's reason? I try compile script without UPX but non result... And i try WMI function but i delete it because does not work on windows 8 :(

Edited by MrKris1224

Share this post


Link to post
Share on other sites
MrKris1224

No, I not have AV and others shit...

Share this post


Link to post
Share on other sites
Jos

mmm "other shit" ....   maybe you aren't aware as you have no early warning system active. ;)

In general, when you are getting the errors you have , it is due to some Anti Malware/Anti Virus program.

Jos

  • Like 1

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

Share this post


Link to post
Share on other sites
MrKris1224

When I said other shit I mean AV, firewall, anti malware programs and ect. I not have that - Pure system. I think the problem is that function. There is no other way to get process parent PID? (No WMI)

Edited by MrKris1224

Share this post


Link to post
Share on other sites
MrKris1224

Ohh my god!!! It works! I'm so stupid... How i can't see it before?! Thanks!!

Where I can give "Best respond" ?!

 

Edited by MrKris1224

Share this post


Link to post
Share on other sites
MrKris1224

Hi again. @Jos your last respond is very good but now again i have problem with error "AutoIt Error - Unable to open the script file". I don't know what's reason then i need your help again.

Share this post


Link to post
Share on other sites
MrKris1224

Anybody can help?

Share this post


Link to post
Share on other sites
Jos

What about you give some more details like:

  • You are running that compiled version of the script?
  • What version are you running?
  • UPX enabled?

Jos


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

Share this post


Link to post
Share on other sites
MrKris1224

I disabled UPX. And compiled as 3.3.12.0 version of autoit. I think the reason is my computer because i give compiled script to my friend and my friend hav same problem. I compile my script then it's 1,041MB size... then after some runnings automaticaly change size to 1,081MB and does not work.

Sorry for english.

Edited by MrKris1224

Share this post


Link to post
Share on other sites
Jos

An EXE should not grow! Is anything added to the PE header for any reason which could screw up the saved script in the PE header?.

Make a copy of the original and compare that with the one that "grows".

Jos

Edited by Jos

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

Share this post


Link to post
Share on other sites
MrKris1224

My EXE grows than does not works and have error "AutoIt Error - Unable to open the script file". I dunno what's reason. my friend have same problem with my script...

Share this post


Link to post
Share on other sites
Jos

again: make a copy of the EXE before running it and then compare them binary after one of them has grown to see what the difference is.

Jos


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

Share this post


Link to post
Share on other sites
MrKris1224

I did not find differences...

Share this post


Link to post
Share on other sites
jvds

if your exe grow for no reason and you say you don't have an antivirus or anti malware, then dont you have a virus binding itself to your compiled exe?

Share this post


Link to post
Share on other sites
MrKris1224

i'm not have antivirus because i'm antyvirus... I know what's virus and what's not virus. I said my friend have same problem with my exe so....

Share this post


Link to post
Share on other sites
Jos

Don't think you answered my last question yet, and what is the next step to check like showing which script is giving the issues when compiled?

Jos


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

Share this post


Link to post
Share on other sites
MrKris1224

I can give you script source. But today i did see this problem with more than one script...

 

#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_SaveSource=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <Winapi.au3>
#include <WinAPIProc.au3>
#include <Array.au3>
Global $aImages[1] = [0]
If $CmdLine[0] Then
    Switch $CmdLine[1]
        Case "/move"
            ClipPut("MOVE|" & $CmdLine[2] & "|" & $CmdLine[3] & "|" & $CmdLine[4])
            While ClipGet() <> "OK"
                Sleep(25)
            WEnd
        Case "/exit"
            ClipPut("EXIT")
        Case "/start"
            ShellExecute(@AutoItExe, "/run", @ScriptDir)
            ClipPut(_Process_GetWin(_WinAPI_GetParentProcess(@AutoItPID), 1))
            While ClipGet() <> "OK"
                Sleep(25)
            WEnd
        Case "/run"
            _GDIPlus_Startup()
            Global $hConsole = WinGetHandle(ClipGet())
            ClipPut("OK")
            Global $g_hGraphics = _GDIPlus_GraphicsCreateFromHWND($hConsole)
            _Graph_Main()
            _GDIPlus_GraphicsDispose($g_hGraphics)
            _GDIPlus_Shutdown()
        Case "/fill"
            ClipPut("FILL|" & $CmdLine[2] & "|" & $CmdLine[3] & "|" & $CmdLine[4] & "|" & $CmdLine[5])
            While ClipGet() <> "OK"
                Sleep(25)
            WEnd
        Case "/erase"
            ClipPut("ERASE|" & $CmdLine[2])
            While ClipGet() <> "OK"
                Sleep(25)
            WEnd
    EndSwitch
EndIf
Exit
Func _Graph_Main()
    Local $aParams, $aSplits, $aDels
    While WinExists($hConsole)
            $aParams = StringSplit(ClipGet(), "|")
            Switch $aParams[1]
                Case "MOVE"
                    If UBound($aParams) = 5 Then
                        For $iMovs = 0 To UBound($aImages) - 1
                            If StringSplit($aImages[$iMovs], "|")[3] = $aParams[4] Then
                                $aImages[$iMovs] = $aParams[2] & "|" & $aParams[3] & "|" & $aParams[4] & "|" & StringSplit($aImages[$iMovs], "|")[4]
                                _WinAPI_RedrawWindow($hConsole)
                            EndIf
                        Next
                    EndIf
                    ClipPut("OK")
                Case "EXIT"
                    _WinAPI_RedrawWindow($hConsole)
                    Exit
                Case "ERASE"
                    If $aParams[2] = "all" Then
                        Global $aImages[1] = [0]
                    Else
                        For $iDels = 0 To UBound($aImages) - 1
                            $aDels = StringSplit($aImages[$iDels], "|")
                            If Not @error Then
                                If $aDels[3] = $aParams[2] Then
                                    $aImages[$iDels] = "EMPTY"
                                    _WinAPI_RedrawWindow($hConsole)
                                EndIf
                            EndIf
                        Next
                    EndIf
                    ClipPut("OK")
                Case "FILL"
                    If UBound($aParams) = 6 Then
                        $iCol = _ArraySearch($aImages, "EMPTY")
                        If @error Then
                            _ArrayAdd($aImages, $aParams[2] & "|" & $aParams[3] & "|" & $aParams[4] & "|" & $aParams[5], 0, @CRLF)
                        Else
                            $aImages[$iCol] = $aParams[2] & "|" & $aParams[3] & "|" & $aParams[4] & "|" & $aParams[5]
                        EndIf
                    EndIf
                    ClipPut("OK")
            EndSwitch
            For $iDraws = 0 To UBound($aImages) - 1
                If $aImages[$iDraws] <> "EMPTY" Then
                    $aSplits = StringSplit($aImages[$iDraws], "|")
                    _Graph_Draw($aSplits[4], $aSplits[1], $aSplits[2])
                EndIf
            Next
        Sleep(25)
    WEnd
EndFunc

Func _Graph_Draw($hFile, $pX, $pY)
    Local $g_hBMP = _GDIPlus_BitmapCreateFromFile($hFile)
    Local $rX = _GDIPlus_ImageGetWidth(_GDIPlus_ImageLoadFromFile($hFile))
    Local $rY = _GDIPlus_ImageGetHeight(_GDIPlus_ImageLoadFromFile($hFile))
    Local $g_hBitmap = _GDIPlus_BitmapCreateFromGraphics($rX, $rY, $g_hGraphics)
    Local $g_hGfxCtxt = _GDIPlus_ImageGetGraphicsContext($g_hBitmap)
    _GDIPlus_GraphicsDrawImage($g_hGfxCtxt, $g_hBMP, 0, 0)
    _GDIPlus_GraphicsDrawImageRect($g_hGraphics, $g_hBitmap, $pX, $pY, $rX, $rY)
    _GDIPlus_GraphicsDispose($g_hGfxCtxt)
    _GDIPlus_BitmapDispose($g_hBitmap)
    _GDIPlus_BitmapDispose($g_hBMP)
EndFunc

Func _Process_GetWin($iPID,$iMode = 0)
    Local $var = WinList()
    For $i = 1 To $var[0][0]
        If $var[$i][0] <> "" And WinGetProcess($var[$i][0]) = $iPID Then
            If $iMode = 0 Then Return $var[$i][0]
            If $iMode <> 0 Then Return $var[$i][1]
        EndIf
    Next
    Return 0
EndFunc

This is command line script for command prompt to display bmp graphic on console window.

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  

×