Terenz Posted November 5, 2014 Posted November 5, 2014 (edited) Hi guys This is a little snip of the code: Global $oShell = ObjCreate("Shell.Application") If Not IsObj($oShell) Then Exit Run("explorer /e, C:\") While 1 $hWnd = WinActive("[REGEXPCLASS:(Explore|Cabinet)WClass]") If $hWnd <> 0 Then For $oWindow In $oShell.Windows() If $oWindow.HWND() = $hWnd Then ExitLoop Next $oTest = $oWindow.Document.SelectedItems() If IsObj($oTest) Then For $oItem In $oTest ConsoleWrite($oItem.Name() & @CR) Next EndIf EndIf Sleep(100) WEnd Pratically it open a folder ( C: ) and wait for the click on a item, it return the filename ( i need to add a flag for avoid the multiple ConsoleWrite but for now i don't care ) The problem is if i close the folder, i have: : ==> The requested action with this object has failed.: $oTest = $oWindow.Document.SelectedItems() $oTest = $oWindow.Document.SelectedItems()^ ERROR And i really don't know how to avoid it. I don't want to close the script, i need it to work "globally" with any folder but if no folder has found...i have the COM error. Solution? Edited November 5, 2014 by Terenz Nothing is so strong as gentleness. Nothing is so gentle as real strength
Moderators JLogan3o13 Posted November 5, 2014 Moderators Posted November 5, 2014 Look at ObjEvent in the help file for how to construct an error handler. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Terenz Posted November 5, 2014 Author Posted November 5, 2014 I'm check it out Nothing is so strong as gentleness. Nothing is so gentle as real strength
water Posted November 5, 2014 Posted November 5, 2014 Usually this is being avoided by waiting for events to occur (menas: wait until the suers selects a file and then process this selection). I don't know which events (if any) the Explorer COM provides. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Terenz Posted November 5, 2014 Author Posted November 5, 2014 Registering the error give more information but nothing else, i'll try to search if someone has the same problem with that COM function used in a loop Nothing is so strong as gentleness. Nothing is so gentle as real strength
water Posted November 5, 2014 Posted November 5, 2014 Remove the MsgBox with the error information. So you simply get an empty function. This function is being called when an COM error occurrs, does nothing and returns to execute the script after the line causing the COM error. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Inververs Posted November 5, 2014 Posted November 5, 2014 $oWindow is not an object when there are no open windows. Thats why $oWindow.Document.SelectedItems() can't process Solution: Global $oShell = ObjCreate("Shell.Application") If Not IsObj($oShell) Then Exit Run("explorer /e, C:\") While 1 $hWnd = WinActive("[REGEXPCLASS:(Explore|Cabinet)WClass]") If $hWnd <> 0 Then For $oWindow In $oShell.Windows() If $oWindow.HWND() = $hWnd Then ExitLoop Next If IsObj($oWindow) And IsObj($oWindow.Document.SelectedItems()) Then For $oItem In $oWindow.Document.SelectedItems() ConsoleWrite($oItem.Name() & @CR) Next EndIf EndIf Sleep(100) WEnd
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