Script not working when MM loses focus. Help ?

Download and get help for different MediaMonkey Addons.

Moderators: Peke, Gurus

Plazma
Posts: 52
Joined: Thu Nov 03, 2005 9:59 am

Script not working when MM loses focus. Help ?

Post by Plazma » Sun Oct 29, 2006 10:01 am

Hey again,

The following code works perfectly when MM is in focus(the window that is currently selected). But I get an error when it loses focus. Does anyone know why this might be - can a WMI query not work when MM isn't in focus?

Anyways, heres what MM say the problem is (when it loses focus).


The error is:
"#-2147417843 -"

and the line which it has trouble with it

Code: Select all

 Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Here's the whole code if you want to look:

Code: Select all

Dim CPS
Dim i
Dim running
Dim running2


Sub OnStartup 
     Script.RegisterEvent SDB, "OnPlay", "CPSroutine"
End Sub



Sub CPSroutine               
     If SDB.Player.CurrentSong.SongID <> CPS Then
          CPS = SDB.Player.CurrentSong.SongID
		
		'Check if YWE is running	
	 strComputer = "." 
	 Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
	 Set running2 = objWMIService.ExecQuery("Select * from Win32_Process where name like 'YahooWid%'")
	 'If YWE is running connect to YWE COM object 
				If running2.count > 0 Then 						
				'Connect to its COM object
			
				End If
				next	
				'Disconnect COM object!!!
			   	 'If YWE isn't running then do nothing		
				End If	
			End If    
	Set running = Nothing
	Set running2 = Nothing
	Set objWMIService = Nothing
	Set strComputer = Nothing
End Sub
Last edited by Plazma on Mon Oct 30, 2006 2:08 pm, edited 2 times in total.

Plazma
Posts: 52
Joined: Thu Nov 03, 2005 9:59 am

Post by Plazma » Mon Oct 30, 2006 1:01 pm

Just wondering if anyone has any thoughts on this at all?

Steegy
Posts: 3452
Joined: Sat Nov 05, 2005 7:17 pm
Location: Belgium
Contact:

Post by Steegy » Mon Oct 30, 2006 1:20 pm

I don't know what the problem is, but is 3 times GetObject("winmgmts... not a bit too much?
Extensions: ExternalTools, ExtractFields, SongPreviewer, LinkedTracks, CleanImport, and some other scripts (Need Help with Addons > List of All Scripts).

Plazma
Posts: 52
Joined: Thu Nov 03, 2005 9:59 am

Post by Plazma » Mon Oct 30, 2006 2:05 pm

Ya, totally - my cutting and pasting didnt work out well on that post. I edited it and now have only one getobject. So it still works perfectly as long as MM is in focus, but not when it gets minimised.

I guess I could just run an external script to do this ... but then it would need to hook up to SDB through com, and I'd rather avoid that.

Plazma
Posts: 52
Joined: Thu Nov 03, 2005 9:59 am

Post by Plazma » Mon Oct 30, 2006 2:30 pm

I figured out the problem - so might as well post the solution:

I found an article on Microsoft's site. I'm not sure if the problem is exactly relayed, but the solution works.

Problem was:
The run-time error occurs because you are trying to make an Automation call to an out-of-process (ActiveX) EXE from within the event notification of the Taskbar Notification Area callback. The value -2147417843 translates to the following error message:
An outgoing call cannot be made since the application is dispatching an input-synchronous call.
Automation clients are required by COM to process input-synchronous calls without interruption, and therefore are prevented from making outgoing Automation calls while processing such messages.
Solution is to create a timer which will carry out the process, but to have the timer wait 10 milliseconds before carryin out the piece of code.

So it works - though it seems ad hoc - hope that makes sense if anyone in the future gets this too.

Post Reply