What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » if (program.open)...

if (program.open)...
Author: Message:
mad_willsy
Junior Member
**


Posts: 21
34 / Male / Flag
Joined: Jan 2007
O.P. if (program.open)...
How do i check to see if a program is open?

Thanks!
Backthebulls.com - Free online games
Upload your own stuff - free!
01-31-2007 05:26 PM
Profile PM Web Find Quote Report
Eljay
Elite Member
*****

Avatar
:O

Posts: 2949
Reputation: 77
– / Male / –
Joined: May 2004
RE: if (program.open)...
code:
function IsProcessRunning(ProcessName){
    var WMI = new ActiveXObject('WbemScripting.SWbemLocator');
    var WMIInstance = WMI.ConnectServer('.', "root\\cimv2");
    var Processes = WMIInstance.ExecQuery("Select * from Win32_Process Where Name = '" + ProcessName + "'");
    return ((Processes.Count > 0) ? true : false);
}

//Example usage
var NotepadRunning = IsProcessRunning("notepad.exe");

EDIT: GeSHi phails :sad:

This post was edited on 01-31-2007 at 05:55 PM by Eljay.
01-31-2007 05:47 PM
Profile PM Find Quote Report
mad_willsy
Junior Member
**


Posts: 21
34 / Male / Flag
Joined: Jan 2007
O.P. RE: if (program.open)...
Thanks - i'll post back if it works!
Backthebulls.com - Free online games
Upload your own stuff - free!
01-31-2007 05:52 PM
Profile PM Web Find Quote Report
hmaster
Senior Member
****

Avatar

Posts: 716
Reputation: 24
33 / Male / Flag
Joined: Nov 2004
RE: if (program.open)...
The color tags messed up:
quote:
Originally posted by Eljay
code:
"root[color=#000099]\\cimv2"[/color]);

Nice function though (Y).

This post was edited on 01-31-2007 at 05:55 PM by hmaster.
[Image: sig.png]
01-31-2007 05:55 PM
Profile PM Web Find Quote Report
Eljay
Elite Member
*****

Avatar
:O

Posts: 2949
Reputation: 77
– / Male / –
Joined: May 2004
RE: if (program.open)...
quote:
Originally posted by hmaster
The color tags messed up
quote:
Originally posted by Eljay
code:
"root[color=#000099]\\cimv2"[/color]);[/color]

Nice function though (Y).

Ah, thanks for pointing it out, yeh MyBB screws up with nested tags (at least I think thats what happened here, too lazy to check!).
Fixed it.
01-31-2007 05:57 PM
Profile PM Find Quote Report
mad_willsy
Junior Member
**


Posts: 21
34 / Male / Flag
Joined: Jan 2007
O.P. RE: if (program.open)...
Ok - i put the function and an if into my script, it returns i cant save it because it has some sort of error.

If I take the if's to see if program is running out, it still wont save. However taking out you function and it saves.

heres the source:

code:
function setNowPlaying(enabled, type, format, title, artist, album, contentID){
    if(typeof(type) == "undefined")type = "Music";
    if(typeof(format) == "undefined")format = "";
    if(typeof(title) == "undefined")title = "";
    if(typeof(artist) == "undefined")artist = "";
    if(typeof(album) == "undefined")album = "";
    if(typeof(contentID) == "undefined")contentID = "";
    enabled = Math.abs(enabled);
   
    var WM_COPYDATA = 0x4A;
   
    //reference
    var song = Interop.Allocate(512);
   
    //change the Music thing to Games or Office or
    song.WriteString(0, "\\0" + type + "\\0" + enabled + "\\0" + format +"\\0" + title +"\\0" + artist + "\\0" + album + "\\0" + contentID + "\\0");
   
   
    //write our copyDataStruct Structure
    var copyDataStruct = Interop.Allocate(12);
    copyDataStruct.WriteDWORD(0, 0x547); //dwData
    copyDataStruct.WriteDWORD(4, song.Size); //cbData
    copyDataStruct.WriteDWORD(8, song.DataPtr);  //lpData
   
   
    //Send it to all open messengers
    var hMSGRUI = 0;
    do{
        hMSGRUI = Interop.Call("User32", "FindWindowExW", 0, hMSGRUI, "MsnMsgrUIManager", 0);
        if(hMSGRUI > 0){
            Interop.Call("User32", "SendMessageW", hMSGRUI, WM_COPYDATA, 0, copyDataStruct);   
        }
    }while(hMSGRUI != 0);
}
function IsProcessRunning(ProcessName){
    var WMI = new ActiveXObject('WbemScripting.SWbemLocator');
    var WMIInstance = WMI.ConnectServer('.', "root\\cimv2");
    var Processes = WMIInstance.ExecQuery("Select * from Win32_Process Where Name = '" + ProcessName + "'");
    return ((Processes.Count > 0) ? true : false);
}

function updateSAMBC() {
var version;
var status;
var timer;
var artist;
var title;
var played;
var sentenceArray;
var copySentenceArray;
var editingSentence;
var file;
var filed;
var XMLDoc;
var playedVar;
var location;
var locationVar;
var locationVara;
var samvar = IsProcessRunning("sambc.exe");
if (samvar == true)
{
    //Create the xml filepath.
    MsgPlus.AddTimer("MessagesTimer", 4000);
    file = MsgPlus.ScriptFilesPath + "\\output.xml";
    //Load the status of the script and the list of messages.
    XMLDoc = new ActiveXObject("Microsoft.XMLDOM");
    XMLDoc.async = false;
    XMLDoc.load(file);
    //Load values from the xml file.
    version = XMLDoc.getElementsByTagName("version");
    timer = XMLDoc.getElementsByTagName("timer");
    artist = XMLDoc.getElementsByTagName("artist");
    title = XMLDoc.getElementsByTagName("title");
    played = XMLDoc.getElementsByTagName("played");
    playedVar = played[Math.floor(Math.random()*played.length)].text;
    setNowPlaying(true, "Music", "{0} - {1}", artist[Math.floor(Math.random()*artist.length)].text, title[Math.floor(Math.random()*title.length)].text + " - " + playedVar);
}
}
function OnEvent_Signin(){
updateSAMBC();
}
function OnEvent_Signout(){
setNowPlaying(false);
}
   
function OnEvent_Timer (timerId){
updateSAMBC();
}

function OnEvent_MenuClicked (MenuItemId, Location, OriginWnd){
    if (MenuItemId=="reset") updateSAMBC();
}

function OnEvent_ChatWndReceiveMessage(wnd, origin, message)
{
var version;
var status;
var timer;
var artist;
var title;
var played;
var sentenceArray;
var copySentenceArray;
var editingSentence;
var file;
var filed;
var XMLDoc;
var playedVar;
var location;
var locationVar;
var locationVara;
var samvar = IsProcessRunning("sambc.exe");
if (samvar == true)
{
    //Create the xml filepath.
    file = MsgPlus.ScriptFilesPath + "\\output.xml";
    //Load the status of the script and the list of messages.
    XMLDoc = new ActiveXObject("Microsoft.XMLDOM");
    XMLDoc.async = false;
    XMLDoc.load(file);
    //Load values from the xml file.
    version = XMLDoc.getElementsByTagName("version");
    timer = XMLDoc.getElementsByTagName("timer");
    artist = XMLDoc.getElementsByTagName("artist");
    title = XMLDoc.getElementsByTagName("title");
    played = XMLDoc.getElementsByTagName("played");
    playedVar = played[Math.floor(Math.random()*played.length)].text;
    location = XMLDoc.getElementsByTagName("location");
    locationVar = location[Math.floor(Math.random()*location.length)].text;
if(origin != Messenger.MyName){
if(message == "!sendsong")
{
wnd.SendFile(locationVar);
}
}
}
}



Did you make a mistake in your function?
So what do I replace with what?


Soz, my .js knowlege is limited - I'm a PHP guy!
Backthebulls.com - Free online games
Upload your own stuff - free!
01-31-2007 06:00 PM
Profile PM Web Find Quote Report
Eljay
Elite Member
*****

Avatar
:O

Posts: 2949
Reputation: 77
– / Male / –
Joined: May 2004
RE: if (program.open)...
Looks like you copied the bbcode for the colouring (which screwed up!).
Take another look at my post, I removed the fancy colouring :P

-----
Also, try not to double post, use the edit button (at the bottom-right corner of your post) instead.
01-31-2007 06:07 PM
Profile PM Find Quote Report
mad_willsy
Junior Member
**


Posts: 21
34 / Male / Flag
Joined: Jan 2007
O.P. RE: if (program.open)...
Thanks it works - just got to add an else to setNowPlaying(false); if its not running and move the times so it still adds another timer event if its not running! THANKS!

I'll post back if I have problems with the else!
It works! YES! - THANKS!
Backthebulls.com - Free online games
Upload your own stuff - free!
01-31-2007 06:13 PM
Profile PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On