Jump to content

How to close MEdiamonkey


Guest M.Temp
 Share

Recommended Posts

Guest M.Temp

Hi,

I would like to close Mediamonkey.

Unfortunatelly winclose("Mediamonkey") doesen't work and I don't know why.....

ProcessClose("Mediamonkey.exe") does work, but it kill's Mediamonkey ==> changes aren't saved. SO is there any function that sends the term not the kill signal to a process?

Thx M.Temp

Link to comment
Share on other sites

Hi,

I would like to close Mediamonkey.

Unfortunatelly winclose("Mediamonkey") doesen't work and I don't know why.....

ProcessClose("Mediamonkey.exe") does work, but it kill's Mediamonkey ==> changes aren't saved. SO is there any function that sends the term not the kill signal to a process?

Thx M.Temp

How do you normally close the program? Record and play back those steps. There are tools to do that for AutoIT such as AU3Record if you are feeling lazy.
Link to comment
Share on other sites

Guest M.Temp

How do you normally close the program? Record and play back those steps. There are tools to do that for AutoIT such as AU3Record if you are feeling lazy.

sry I'm not sure weather I have understood you

well normally I close it by clicking on the X-Button

Link to comment
Share on other sites

sry I'm not sure weather I have understood you

well normally I close it by clicking on the X-Button

I think what Confuzzled meant is "File/Close" or something along that line. To Just click on the X-Button would require knowing the co-ordinates which could change depanding on the screen resolution.


Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Link to comment
Share on other sites

Welcome to the forums!

Sometimes windows have a custom title bar, so they may display one thing as the caption while masquerading to Windows as another. Have you used AutoIt Window Info on the window in question to determine how it sees the window's title?

Link to comment
Share on other sites

  • 1 year later...

Hi. I want to do something like the topicstarter of this thread.

I wan't to close for example dreamweaver, but let dreamweaver handle the closing.

so if there is work open that is not saved. it can be saved and then closed.

If I use processclose all the work that is open will just vanish.

Is there any way to accomplish this?

Edited by thor918
Link to comment
Share on other sites

WinClose :whistle:

thanks. but I need to close down application by filepath and winclose dosen't take multiple windows with same title into consern(it's not needed in the dreamweaver example. but good to have in the future use)

I have almost an working code for it. but "_WinGetInfoByPID" gets the handle wrong sometimes.

I haven't looked too closly on that yet.

#include <misc.au3>
#include <Process.au3>


$KillProcessFilePath = "K:\Dreamweaver 8\Dreamweaver.exe"

$myPID = findPIDbyPath($KillProcessFilePath)

if ($myPID) then;Process found
        local $myPIDname = _ProcessGetName($myPID)
        local $myPIDinfo = _WinGetInfoByPID(Number($myPID))
        local $myPIDhwnd = $myPIDinfo[1][2]
        local $myPIDtitle = $myPIDinfo[1][1]

        MsgBox(4096, "test" , $myPIDhwnd , 10)
;closeApplicationNicly($myPIDhwnd);
      ;ProcessClose($myPID); will kill the process. no question asked   
EndIf

Func closeApplicationNicly($hwnd);process will shutdown nicely.program will notify if something is needed before it can shutdown
    Local Const $WM_CLOSE = 0x0010
    _SendMessage($hwnd, $WM_CLOSE, 0, 0);
EndFunc
    
Func findPIDbyPath($path)
    Local $a_ProcessList = ProcessList()
    For $iProcessList = 1 To $a_ProcessList[0][0]   
        If StringInStr(_PidGetPath($a_ProcessList[$iProcessList][1]), $path) Then;if we match a process with correct path
            Return $a_ProcessList[$iProcessList][1]
        EndIf
    Next
    Return  False
EndFunc

Func _PidGetPath(ByRef $PID); taken from hooch http://www.autoitscript.com/forum/index.php?showtopic=24897&pid=174656&mode=threaded&start=#entry174656
    Local $Process, $Modules, $Ret
    Const $PROCESS_QUERY_INFORMATION = 0x0400
    Const $PROCESS_VM_READ = 0x0010
    $Process = DLLCall("kernel32.dll","hwnd","OpenProcess","int", _
            BitOR($PROCESS_QUERY_INFORMATION,$PROCESS_VM_READ),"int",0,"int",$PID)
    If $Process[0] = 0 Then Return SetError(1)
    
    $Modules = DLLStructCreate("int[1024]")
    DLLCall("psapi.dll","int","EnumProcessModules","hwnd",$Process[0],"ptr",DllStructGetPtr($Modules), _
            "int",DllStructGetSize($Modules),"int_ptr",0)
    
    $Ret = DLLCall("psapi.dll","int","GetModuleFileNameEx","hwnd",$Process[0],"int",DllStructGetData($Modules,1), _
            "str","","int",2048)
    $Modules = 0
    If StringLen($Ret[3]) = 0 Then Return SetError(1)
    Return $Ret[3]
EndFunc

;
Func _WinGetInfoByPID($sPID);taken from GtaSpider http://www.autoitscript.com/forum/index.php?showtopic=39567&pid=295135&mode=threaded&start=#entry295135
    Local $aPList = ProcessList(), $iPID
    For $iiCount = 1 To $aPList[0][0]
        If $aPList[$iiCount][1] = $sPID Then
            If $sPID = 0 Then Return 0
            $iPID &= $aPList[$iiCount][1] & Chr(01)
        EndIf
    Next
    $iPID = StringSplit($iPID, Chr(01))
    If $iPID = 0 Then Return SetError(1, 0, 0)
    Local $aStoreHwndAndText[2][9], $nCount = 1
    $OptWSC = Opt('WinSearchChildren', 1)
    $OptWDHT = Opt('WinDetectHiddenText', 1)
    Local $aWinList = WinList()
    For $iCount = 1 To $aWinList[0][0]
        For $xCount = 1 To $iPID[0]
            If WinGetProcess($aWinList[$iCount][1]) = $iPID[$xCount] And _
                    $aWinList[$iCount][0] <> '' Then
                Local $aWinPos = WinGetPos($aWinList[$iCount][1])
                Local $aWinClient = WinGetClientSize($aWinList[$iCount][1])
                $nCount += 1
                ReDim $aStoreHwndAndText[$nCount][9]
                $aStoreHwndAndText[$nCount - 1][1] = $aWinList[$iCount][0]
                $aStoreHwndAndText[$nCount - 1][2] = $aWinList[$iCount][1]
                $aStoreHwndAndText[$nCount - 1][3] = WinGetText($aWinList[$iCount][1])
                $aStoreHwndAndText[$nCount - 1][4] = $aWinPos[0]
                $aStoreHwndAndText[$nCount - 1][5] = $aWinPos[1]
                $aStoreHwndAndText[$nCount - 1][6] = $aWinClient[0]
                $aStoreHwndAndText[$nCount - 1][7] = $aWinClient[1]
                $aStoreHwndAndText[$nCount - 1][8] = WinGetClassList($aWinList[$iCount][1])
            EndIf
        Next
    Next
    Opt('WinSearchChildren', $OptWSC)
    Opt('WinDetectHiddenText', $OptWDHT)
    If $nCount = 1 Then Return SetError(2, 0, 0)
    Return $aStoreHwndAndText
EndFunc ;==>_WinGetInfoByPID
Edited by thor918
Link to comment
Share on other sites

hmm it seems connected to if I have clicked on something in the application.

if I haven't clicked on something. it reports different handles each time. I haven't investigatet it yet, but I think the handles reported is to components inside the same applications.

so an easy solution would perhaps have it killed if it does not shutdown nicly...

shouldn't be any problem. because if the app isn't used it shouldn't be any need to shutdown it nicly..

thanks. but I need to close down application by filepath and winclose dosen't take multiple windows with same title into consern(it's not needed in the dreamweaver example. but good to have in the future use)

I have almost an working code for it. but "_WinGetInfoByPID" gets the handle wrong sometimes.

I haven't looked too closly on that yet.

#include <misc.au3>
#include <Process.au3>
$KillProcessFilePath = "K:\Dreamweaver 8\Dreamweaver.exe"

$myPID = findPIDbyPath($KillProcessFilePath)

if ($myPID) then;Process found
        local $myPIDname = _ProcessGetName($myPID)
        local $myPIDinfo = _WinGetInfoByPID(Number($myPID))
        local $myPIDhwnd = $myPIDinfo[1][2]
        local $myPIDtitle = $myPIDinfo[1][1]

        MsgBox(4096, "test" , $myPIDhwnd , 10)
;closeApplicationNicly($myPIDhwnd);
;ProcessClose($myPID); will kill the process. no question asked 
EndIf

Func closeApplicationNicly($hwnd);process will shutdown nicely.program will notify if something is needed before it can shutdown
    Local Const $WM_CLOSE = 0x0010
    _SendMessage($hwnd, $WM_CLOSE, 0, 0);
EndFunc
    
Func findPIDbyPath($path)
    Local $a_ProcessList = ProcessList()
    For $iProcessList = 1 To $a_ProcessList[0][0]   
        If StringInStr(_PidGetPath($a_ProcessList[$iProcessList][1]), $path) Then;if we match a process with correct path
            Return $a_ProcessList[$iProcessList][1]
        EndIf
    Next
    Return  False
EndFunc

Func _PidGetPath(ByRef $PID); taken from hooch http://www.autoitscript.com/forum/index.php?showtopic=24897&pid=174656&mode=threaded&start=#entry174656
    Local $Process, $Modules, $Ret
    Const $PROCESS_QUERY_INFORMATION = 0x0400
    Const $PROCESS_VM_READ = 0x0010
    $Process = DLLCall("kernel32.dll","hwnd","OpenProcess","int", _
            BitOR($PROCESS_QUERY_INFORMATION,$PROCESS_VM_READ),"int",0,"int",$PID)
    If $Process[0] = 0 Then Return SetError(1)
    
    $Modules = DLLStructCreate("int[1024]")
    DLLCall("psapi.dll","int","EnumProcessModules","hwnd",$Process[0],"ptr",DllStructGetPtr($Modules), _
            "int",DllStructGetSize($Modules),"int_ptr",0)
    
    $Ret = DLLCall("psapi.dll","int","GetModuleFileNameEx","hwnd",$Process[0],"int",DllStructGetData($Modules,1), _
            "str","","int",2048)
    $Modules = 0
    If StringLen($Ret[3]) = 0 Then Return SetError(1)
    Return $Ret[3]
EndFunc

;
Func _WinGetInfoByPID($sPID);taken from GtaSpider http://www.autoitscript.com/forum/index.php?showtopic=39567&pid=295135&mode=threaded&start=#entry295135
    Local $aPList = ProcessList(), $iPID
    For $iiCount = 1 To $aPList[0][0]
        If $aPList[$iiCount][1] = $sPID Then
            If $sPID = 0 Then Return 0
            $iPID &= $aPList[$iiCount][1] & Chr(01)
        EndIf
    Next
    $iPID = StringSplit($iPID, Chr(01))
    If $iPID = 0 Then Return SetError(1, 0, 0)
    Local $aStoreHwndAndText[2][9], $nCount = 1
    $OptWSC = Opt('WinSearchChildren', 1)
    $OptWDHT = Opt('WinDetectHiddenText', 1)
    Local $aWinList = WinList()
    For $iCount = 1 To $aWinList[0][0]
        For $xCount = 1 To $iPID[0]
            If WinGetProcess($aWinList[$iCount][1]) = $iPID[$xCount] And _
                    $aWinList[$iCount][0] <> '' Then
                Local $aWinPos = WinGetPos($aWinList[$iCount][1])
                Local $aWinClient = WinGetClientSize($aWinList[$iCount][1])
                $nCount += 1
                ReDim $aStoreHwndAndText[$nCount][9]
                $aStoreHwndAndText[$nCount - 1][1] = $aWinList[$iCount][0]
                $aStoreHwndAndText[$nCount - 1][2] = $aWinList[$iCount][1]
                $aStoreHwndAndText[$nCount - 1][3] = WinGetText($aWinList[$iCount][1])
                $aStoreHwndAndText[$nCount - 1][4] = $aWinPos[0]
                $aStoreHwndAndText[$nCount - 1][5] = $aWinPos[1]
                $aStoreHwndAndText[$nCount - 1][6] = $aWinClient[0]
                $aStoreHwndAndText[$nCount - 1][7] = $aWinClient[1]
                $aStoreHwndAndText[$nCount - 1][8] = WinGetClassList($aWinList[$iCount][1])
            EndIf
        Next
    Next
    Opt('WinSearchChildren', $OptWSC)
    Opt('WinDetectHiddenText', $OptWDHT)
    If $nCount = 1 Then Return SetError(2, 0, 0)
    Return $aStoreHwndAndText
EndFunc;==>_WinGetInfoByPID
Edited by thor918
Link to comment
Share on other sites

hmm it seems connected to if I have clicked on something in the application.

if I haven't clicked on something. it reports different handles each time. I haven't investigatet it yet, but I think the handles reported is to components inside the same applications.

so an easy solution would perhaps have it killed if it does not shutdown nicly...

shouldn't be any problem. because if the app isn't used it shouldn't be any need to shutdown it nicly..

hmmm. seems it's using window title "WinGetProcess" in the _WinGetInfoByPID

so this method wasen't optimal either. strange how finding the top hwnd of a prossessid is so difficult.

and I haven't found any api that can shutdown a app nicly directly.

Link to comment
Share on other sites

hmmm. seems it's using window title "WinGetProcess" in the _WinGetInfoByPID

so this method wasen't optimal either. strange how finding the top hwnd of a prossessid is so difficult.

and I haven't found any api that can shutdown a app nicly directly.

OK. only going trough visble windows that have a title, seemed to hardening the code to work every time for dreamweaver.

But still. not sure if this is the best way to do this.

I read that api TerminateAppEnum() posts WM_CLOSE to all windows whose PID. matches your process's.

would be sweet if a soft closing of application where built into the autoit api (not by title, but by filename or pid)

#include <misc.au3>
#include <Process.au3>


$KillProcessFilePath = "K:\Dreamweaver 8\Dreamweaver.exe"

$myPID = findPIDbyPath($KillProcessFilePath)

    
if ($myPID) then;Process found
        local $myPIDname = _ProcessGetName($myPID)
        local $myPIDhwnd = _WinGetHwndByPID(Number($myPID))
        
;msgBox(4096, "test" ,  $myPIDhwnd, 0);TerminateApp
        closeApplicationNicly($myPIDhwnd);
     ;ProcessClose($myPID); will kill the process. no question asked    
EndIf

Func closeApplicationNicly($hwnd);process will shutdown nicely.program will notify if something is needed before it can shutdown
    Local Const $WM_CLOSE = 0x0010
    _SendMessage($hwnd, $WM_CLOSE, 0, 0);
EndFunc
    
Func findPIDbyPath($path)
    Local $a_ProcessList = ProcessList()
    For $iProcessList = 1 To $a_ProcessList[0][0]   
        If StringInStr(_PidGetPath($a_ProcessList[$iProcessList][1]), $path) Then;if we match a process with correct path
            Return $a_ProcessList[$iProcessList][1]
        EndIf
    Next
    Return  False
EndFunc

Func _PidGetPath(ByRef $PID); taken from hooch http://www.autoitscript.com/forum/index.php?showtopic=24897&pid=174656&mode=threaded&start=#entry174656
    Local $Process, $Modules, $Ret
    Const $PROCESS_QUERY_INFORMATION = 0x0400
    Const $PROCESS_VM_READ = 0x0010
    $Process = DLLCall("kernel32.dll","hwnd","OpenProcess","int", _
            BitOR($PROCESS_QUERY_INFORMATION,$PROCESS_VM_READ),"int",0,"int",$PID)
    If $Process[0] = 0 Then Return SetError(1)
    
    $Modules = DLLStructCreate("int[1024]")
    DLLCall("psapi.dll","int","EnumProcessModules","hwnd",$Process[0],"ptr",DllStructGetPtr($Modules), _
            "int",DllStructGetSize($Modules),"int_ptr",0)
    
    $Ret = DLLCall("psapi.dll","int","GetModuleFileNameEx","hwnd",$Process[0],"int",DllStructGetData($Modules,1), _
            "str","","int",2048)
    $Modules = 0
    If StringLen($Ret[3]) = 0 Then Return SetError(1)
    Return $Ret[3]
EndFunc

;
Func _WinGetHwndByPID($sPID);taken from GtaSpider http://www.autoitscript.com/forum/index.php?showtopic=39567&pid=295135&mode=threaded&start=#entry295135
    Local $aPList = ProcessList(), $iPID
    For $iiCount = 1 To $aPList[0][0]
        If $aPList[$iiCount][1] = $sPID Then
            If $sPID = 0 Then Return 0
            $iPID &= $aPList[$iiCount][1] & Chr(01)
        EndIf
    Next
    $iPID = StringSplit($iPID, Chr(01))
    If $iPID = 0 Then Return SetError(1, 0, 0)
    Local $aStoreHwndAndText[2][9], $nCount = 1
    $OptWSC = Opt('WinSearchChildren', 1);
    $OptWDHT = Opt('WinDetectHiddenText', 1)
    Local $aWinList = WinList()
    For $iCount = 1 To $aWinList[0][0]
        For $xCount = 1 To $iPID[0]
            If WinGetProcess($aWinList[$iCount][1]) = $iPID[$xCount] And _
                    $aWinList[$iCount][0] <> '' AND IsVisible($aWinList[$iCount][1]) Then

                $aStoreHwndAndText[$nCount - 1][2] = $aWinList[$iCount][1]
       
                Return $aStoreHwndAndText[$nCount - 1][2]; quick hack
            EndIf
        Next
    Next
    Opt('WinSearchChildren', $OptWSC)
    Opt('WinDetectHiddenText', $OptWDHT)
EndFunc;==>_WinGetHwndByPID 

Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then 
    Return 1
  Else
    Return 0
  EndIf

EndFunc
Edited by thor918
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...