eignxing Posted August 13, 2009 Share Posted August 13, 2009 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. Link to comment Share on other sites More sharing options...
Demonic Posted August 13, 2009 Share Posted August 13, 2009 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. Link to comment Share on other sites More sharing options...
Juvigy Posted August 13, 2009 Share Posted August 13, 2009 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. Link to comment Share on other sites More sharing options...
eignxing Posted August 13, 2009 Author Share Posted August 13, 2009 (edited) 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 August 13, 2009 by Jon8763 Link to comment Share on other sites More sharing options...
eignxing Posted August 13, 2009 Author Share Posted August 13, 2009 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now