WoodGrain Posted December 18, 2016 Share Posted December 18, 2016 (edited) Hi All, I've coded the small script below, but it can't seem to get the instance of Windows Media player as it keeps going to @error, I've not used com objects before so any assistance would be appreciate. I already have WMP open and minimised. I retrieved "WMPlayerApp" from the AutoIT info tool, I've included a copy below. I'm using these sources:https://msdn.microsoft.com/en-us/library/dd564085.aspxhttps://msdn.microsoft.com/en-us/library/dd564018.aspx $oWMP = ObjGet("", "WMPlayerApp") If @error Then MsgBox(0, "Can't get WMP", "Couldn't connect to the WMP instance") Exit EndIf $wmpPlayState = $oWMP.playState MsgBox(0, "Play State", $wmpPlayState) $wmpSongName = $oWMP.currentMedia.name MsgBox(0, "Play State", $wmpSongName) I've also seen references to the below, but I want to get an existing open WMP: ObjCreate("wmplayer.OCX") and have looked at the WMP.udf but can't see how it will do either of the functions I've coded above. Quote >>>> Window <<<< Title: Windows Media Player Class: WMPlayerApp Position: -7, -7 Size: 1295, 697 Style: 0x17CF0000 ExStyle: 0x00040100 Handle: 0x000000000008060C >>>> Control <<<< Class: Instance: ClassnameNN: Name: Advanced (Class): ID: Text: Position: Size: ControlClick Coords: Style: ExStyle: Handle: >>>> Mouse <<<< Position: 713, 2 Cursor ID: 2 Color: 0x8DC8FB >>>> StatusBar <<<< >>>> ToolsBar <<<< >>>> Visible Text <<<< WMPAppHost LibraryContainer View Toolbar Command Toolbar Search PrimaryListView Library Treeview List Pane Right Toolbar List Pane Command Bar Unsaved list PlayHistory Back Toolbar PlayHistory Forward Toolbar BasketListView >>>> Hidden Text <<<< Search Edit Box Details Pane Library Navigation Pane Now Playing list Edited December 18, 2016 by WoodGrain Link to comment Share on other sites More sharing options...
WoodGrain Posted December 18, 2016 Author Share Posted December 18, 2016 Or if there's a way of doing with the UDF I'm happy to do that too. Link to comment Share on other sites More sharing options...
water Posted December 19, 2016 Share Posted December 19, 2016 Add a COM error handler es described in the help file for ObjEvent to get more detailed error information. 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 Link to comment Share on other sites More sharing options...
water Posted December 19, 2016 Share Posted December 19, 2016 Use ObjGet to access a running instance and ObjCreate to create a new one. So I suggest: $oWMP = ObjGet("", "wmplayer.OCX") ; Connect to a running instance If @error or Not IsObj($oWMP) Then $oWMP = ObjCreate("wmplayer.OCX") If @error or Not IsObj($oWMP) Then Exit MsgBox(0, "Error", "Could not create object. @error = " & @error & ", @extended = " & @extended) EndIf 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 Link to comment Share on other sites More sharing options...
WoodGrain Posted December 19, 2016 Author Share Posted December 19, 2016 Thanks, I've only recently started using @error, good to know I can get more info this way. I added @error to my code and it returned -2147352570 and extended is 0 even though WMP is running minimised. I left out the ObjCreate as I just want to get the current details if WMP is running. I'm running WMP 12 if that makes any difference? $oWMP = ObjGet("", "wmplayer.OCX") If @error Then MsgBox(0, "Can't get WMP", "Couldn't connect to the WMP instance:" & @CRLF & @error & @CRLF & @extended) Exit EndIf $wmpPlayState = $oWMP.playState MsgBox(0, "Play State", $wmpPlayState) $wmpSongName = $oWMP.currentMedia.name MsgBox(0, "Play State", $wmpSongName) Thanks. Link to comment Share on other sites More sharing options...
water Posted December 19, 2016 Share Posted December 19, 2016 This return value stands for (0x80020006): Unknown name. 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 Link to comment Share on other sites More sharing options...
WoodGrain Posted December 20, 2016 Author Share Posted December 20, 2016 Ok, so it brings me back to getting this correct: ObjGet("", "wmplayer.OCX") "wmplayer.ocx" I assume is incorrect? In my original post the info tool said the class was WMPlayerApp? Link to comment Share on other sites More sharing options...
trancexx Posted December 20, 2016 Share Posted December 20, 2016 Window class name has nothing to to with this. Where did you get the idea it does?? Anyway, ObjGet() used like this will get you reference to the object registered in the ROT (google if you don't know what that is). If the object is not registered there the function will fail. My guess is that's happening here. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
WoodGrain Posted December 21, 2016 Author Share Posted December 21, 2016 Hi Trancexx, From the help file: ObjGet ( "filename" [, "classname" [, instance]] ) Have I misread it? Ok, I've googled ROT, and have used a ROT Viewer to retrieve the attached information, but it doesn't mean much to me, not sure how to determine what the objects are? Thanks. 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