Jump to content
Sign in to follow this  
eignxing

Close any window open only from a certain drive

Recommended Posts

eignxing

I have a removable drive with a file located at F:\testdir\subdir\file.txt

I need a script to close an open window if there is one opened on the removable drive so I can safely remove it without problems.

I've tried using If winexists("Removable Drive (F:)") then winclose("Removable Drive (F:)") but that only works if the open window is the root removable drive... there could be other windows with say "subdir" open on the parent drive that should not automatically be closed.

Just to be clear, say I have a window open with the path F:\testdir\subdir\ and I also have a window open with the path C:\subdir\. They both have the same window title, but only the window open on F:\ should be closed.

Does anyone know of a way to do this? I'm just having a hard time thinking of how to solve this right now.

Share this post


Link to post
Share on other sites
Demonic

Not quite sure on closing directorys and such as they all fall under explorer.exe, but if your speaking about having processes open from the removable device, you can use this UDF by Ascend4nt:

http://www.autoitscript.com/forum/index.php?showtopic=89183&st=0&p=640872&#entry640872

you should be able to check through your process list, and check for the string 'f:\' in it. It returns the full path, so the process will either return 'c:\etc\etc\etc' or 'f:\etc\etc\etc' and from there you can have it close the processes.

Other then that, I'm not sure.

Share this post


Link to post
Share on other sites
Juvigy

It is better to click on the "safely remove hardware" on the taskbar and then you can unplug the USB safely.

How to do that is another thing that i havent dug into.

Share this post


Link to post
Share on other sites
eignxing

Thanks, I've found how to remove the device automatically and safely while clearing the memory (there is a post on the forum which works well somewhere), but it won't work unless all the processes are closed. I guess what I'm really after is a way to get the path of a target window or process. Actually I just need the path of a target window.

Edited by Jon8763

Share this post


Link to post
Share on other sites
eignxing

I solved the problem. Thanks to Nahuel for the code here:

http://www.autoitscript.com/forum/index.php?showtopic=86825&st=0&p=623064&hl=get%20window%20path&fromsearch=1&#entry623064

$ExWin  = "[REGEXPCLASS:(Cabinet|Explore)WClass]"
$AddBar = "[CLASS:Edit; INSTANCE:1]"

$Explorers = WinList($ExWin)
Dim $DirsOp[$Explorers[0][0]]

For $i=1 To $Explorers[0][0]
    $DirsOp[$i-1] = ControlGetText($Explorers[$i][1],"",$AddBar)
    If StringInStr($DirsOp[$i-1], "F:\") <> 0 Then
        WinClose($Explorers[$i][1])
    EndIf
Next

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.