Jump to content
Sign in to follow this  
FastHelper

how to close a window?

Recommended Posts

FastHelper

how can i close a window which is not associate with any program? like if any folder or drive is opened.

i know i can do like this:

if winexists("Name") Then
    WinClose ("Name") 'or WinKill
EndIf

but how can i close all opened folders? or drives.

thanks for the help


sorry for my spelling mistakes. its due to be fast !!!

Share this post


Link to post
Share on other sites
martin

how can i close a window which is not associate with any program? like if any folder or drive is opened.

i know i can do like this:

if winexists("Name") Then
    WinClose ("Name") 'or WinKill
EndIf

but how can i close all opened folders? or drives.

thanks for the help

You might consider that this is a bit drastic but

ProcessClose("explorer.exe")
Sleep(3000)
ShellExecute("explorer.exe")

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
monoceres

Maybe this?

$array=WinList()
$ePID=ProcessExists("explorer.exe")
For $i=1 To Ubound($array)-1
    If WinGetProcess($array[$i][0])=$ePID Then
        WinClose($array[$i][0])
    EndIf
Next

:)

Edited by monoceres

Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites
martin

Maybe this?

$array=WinList()
$ePID=ProcessExists("explorer.exe")
For $i=1 To Ubound($array)-1
    If WinGetProcess($array[$i][0])=$ePID Then
        WinClose($array[$i][0])
    EndIf
Next

:)

That's much better monoceres :) Shearing the sheep is better than shooting it I suppose.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
FastHelper

Maybe this?

$array=WinList()
$ePID=ProcessExists("explorer.exe")
For $i=1 To Ubound($array)-1
    If WinGetProcess($array[$i][0])=$ePID Then
        WinClose($array[$i][0])
    EndIf
Next

:)

thanks for the help but after closing the folder window it prompts for shutdown. how can i avoid not to ask for shutdown.

sorry for my spelling mistakes. its due to be fast !!!

Share this post


Link to post
Share on other sites
FastHelper

@ monocers

shutdown problem fixed by this:

$array=WinList()
$ePID=ProcessExists("explorer.exe")
For $i=1 To Ubound($array)-1
    If WinGetProcess($array[$i][0])=$ePID Then
        WinClose($array[$i][0])
        if WinExists("") Then
            send("{Esc}")
        EndIf
    EndIf
Next

but still want to know you idea because i know sending esc may close some running apps.


sorry for my spelling mistakes. its due to be fast !!!

Share this post


Link to post
Share on other sites
food

how can i close a window which is not associate with any program? like if any folder or drive is opened.

i know i can do like this:

if winexists("Name") Then
    WinClose ("Name") 'or WinKill
EndIf

but how can i close all opened folders? or drives.

thanks for the help

when you open autoit windows info you will find "class" of programe you want close after write code

if winexists("Name") Then

WinClose ("Name") 'or WinKill

EndIf

ex: notepad is

[class:Notepad]

and write:

if winexists("[class:Notepad]") then

winclose("[class:Notepad]")

endif

Share this post


Link to post
Share on other sites
FreeFry

He could use something like this:

#include <WinAPI.au3>

$aWindows = _ProcessGetWinEx("explorer.exe", "CabinetWClass")
For $i = 1 To $aWindows[0]
    WinClose($aWindows[$i])
Next

Func _ProcessGetWinEx($ivPid, $svClass = "", $svTitle = "", $svText = "")
   
    $ivPid = ProcessExists($ivPid)
    If Not $ivPid Then Return(SetError(1, 0, 0))
    
    Local $avwArray = WinList()
    Local $avRet[1] = [0]
   
    For $i = 1 To $avwArray[0][0]
;~      ConsoleWrite($avwArray[$i][0] & @LF)
        If WinGetProcess($avwArray[$i][1]) = $ivPid Then
            If $svClass = "" Or _WinAPI_GetClassName($avwArray[$i][1]) = $svClass Then
                If ($svTitle = "" Or $avwArray[$i][0] = $svTitle) And ($svText = "" Or StringInStr(WinGetText($avwArray[$i][1]), $svText)) Then
                    $avRet[0] += 1
                    ReDim $avRet[$avRet[0]+1]
                    $avRet[$avRet[0]] = $avwArray[$i][1]
                EndIf
            EndIf
        EndIf
    Next
   
    Return $avRet
   
EndFunc

Share this post


Link to post
Share on other sites
FastHelper

He could use something like this:

#include <WinAPI.au3>

$aWindows = _ProcessGetWinEx("explorer.exe", "CabinetWClass")
For $i = 1 To $aWindows[0]
    WinClose($aWindows[$i])
Next

Func _ProcessGetWinEx($ivPid, $svClass = "", $svTitle = "", $svText = "")
   
    $ivPid = ProcessExists($ivPid)
    If Not $ivPid Then Return(SetError(1, 0, 0))
    
    Local $avwArray = WinList()
    Local $avRet[1] = [0]
   
    For $i = 1 To $avwArray[0][0]
;~      ConsoleWrite($avwArray[$i][0] & @LF)
        If WinGetProcess($avwArray[$i][1]) = $ivPid Then
            If $svClass = "" Or _WinAPI_GetClassName($avwArray[$i][1]) = $svClass Then
                If ($svTitle = "" Or $avwArray[$i][0] = $svTitle) And ($svText = "" Or StringInStr(WinGetText($avwArray[$i][1]), $svText)) Then
                    $avRet[0] += 1
                    ReDim $avRet[$avRet[0]+1]
                    $avRet[$avRet[0]] = $avwArray[$i][1]
                EndIf
            EndIf
        EndIf
    Next
   
    Return $avRet
   
EndFunc

thanks buddy, its working perfect.


sorry for my spelling mistakes. its due to be fast !!!

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.