Sign in to follow this  
Followers 0
Diana (Cda)

List apps running out of specific list?

4 posts in this topic

I started to write a script but got stumped right away. Realized that I don't know what AutoIt function to use.

Here's as far as I got:

$MultimediaPlayer_01 = "coolplayer.exe"
$MultimediaPlayer_02 = "bsplayer.exe"
$MultimediaPlayer_03 = "mplayerc.exe"
$MultimediaPlayer_04 = "screamer.exe"
$MultimediaPlayer_05 = "winamp.exe"
$MultimediaPlayer_06 = "wv_player.exe"

MsgBox("Multimedia Players:","The following players are currently active:" ...

I took a look at the handful of processes running scripts I have and they didn't help.

(Crossing fingers that this doesn't involve arrays as that's still a new frontier for me to which I haven't even begun to master the rudiments. Don't understand them yet <g>.)

I started to do an If statement but then realized that OR or AND both won't work. It's not a question of If this OR if that nor is it a question of If this AND if that ... it's just a list of which of the players above are actually playing.

I've always had to do this manually via visually scanning the task manager but that's a pain. I'd like to save the time (it's to do with a volume control script).

Thanks in advance!

:)

Share this post


Link to post
Share on other sites



Are you looking for something like this?

Global $MultimediaPlayer[7]
$MultimediaPlayer[0] = 6
$MultimediaPlayer[1] = "coolplayer.exe"
$MultimediaPlayer[2] = "bsplayer.exe"
$MultimediaPlayer[3] = "mplayerc.exe"
$MultimediaPlayer[4] = "screamer.exe"
$MultimediaPlayer[5] = "winamp.exe"
$MultimediaPlayer[6] = "wv_player.exe"

MsgBox(0,"Multimedia Players:","The following players are currently active: " & GetCurrent_MPlayers())

Func GetCurrent_MPlayers()
    Local $RESULT
    For $INDEX = 1 To $MultimediaPlayer[0]
        If ProcessExists($MultimediaPlayer[$INDEX]) <> 0 Then
            $RESULT &= $MultimediaPlayer[$INDEX] & @CRLF
        EndIf
    Next
    If $RESULT = "" Then
        Return "None"
    Else
        Return StringTrimRight($RESULT,2)
    EndIf
EndFunc

When the words fail... music speaks

Share this post


Link to post
Share on other sites

Andreik, that works perfectly. I just added a couple of lines breaks in the messagebox if that's okay.

MsgBox(0,"Multimedia Players:","The following players are currently active: " & @CRLF & @CRLF & GetCurrent_MPlayers())

I tested it out by opening and closing a few apps at a time. It caught them all! Beautiful.

Just out of curiosity, and I should have asked in my initial message on how to do that, but I honestly forgot to. The executable file name for each is what is listed in the task manager. Would it be something very difficult to have AI display the app name in the message box ... i.e., coolplayer.exe refers to CoolPlayer, bsplayer.exe to BSPlayer (yeah, _very_ weird name; but it's a great player!), screamer.exe is a great freeware streaming radio player called ScreamerRadio, another very weirdly named app! No need to re-write anything or add anything, just curious as to the approach, is all.

I love the code as is. Thank your for this. I thought I was going to have to spend days and days on this and I can't figure out yet how you reduced something so complicated to just a handful of lines of code! <g>

Thanks! :)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

To get window name from process should not be very hard. Just use WinGetProcess() and compare the resulted PID with th PID returned by ProcessExists() function.

LE: something like that

Global $MultimediaPlayer[7]
$MultimediaPlayer[0] = 6
$MultimediaPlayer[1] = "coolplayer.exe"
$MultimediaPlayer[2] = "bsplayer.exe"
$MultimediaPlayer[3] = "mplayerc.exe"
$MultimediaPlayer[4] = "screamer.exe"
$MultimediaPlayer[5] = "winamp.exe"
$MultimediaPlayer[6] = "wv_player.exe"

MsgBox(0,"Multimedia Players:","The following players are currently active: " & GetCurrent_MPlayers())

Func GetCurrent_MPlayers()
    Local $RESULT
    For $INDEX = 1 To $MultimediaPlayer[0]
        $PID = ProcessExists($MultimediaPlayer[$INDEX])
        If $PID <> 0 Then
            $RESULT &= GetWindowName($PID) & @CRLF
        EndIf
    Next
    If $RESULT = "" Then
        Return "None"
    Else
        Return StringTrimRight($RESULT,2)
    EndIf
EndFunc

Func GetWindowName($PID)
    Local $WIN = WinList()
    If IsArray($WIN) Then
        For $INDEX = 1 To $WIN[0][0]
            If WinGetProcess($WIN[$INDEX][1]) = $PID Then Return $WIN[$INDEX][0]
        Next
    EndIf
    Return ""
EndFunc
Edited by Andreik

When the words fail... music speaks

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  
Followers 0