Shoutbox

if (program.open)... - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: if (program.open)... (/showthread.php?tid=71239)

if (program.open)... by mad_willsy on 01-31-2007 at 05:26 PM

How do i check to see if a program is open?

Thanks!


RE: if (program.open)... by Eljay on 01-31-2007 at 05:47 PM

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:
RE: if (program.open)... by mad_willsy on 01-31-2007 at 05:52 PM

Thanks - i'll post back if it works!


RE: if (program.open)... by hmaster on 01-31-2007 at 05:55 PM

The color tags messed up:

quote:
Originally posted by Eljay
code:
"root[color=#000099]\\cimv2"[/color]);

Nice function though (Y).
RE: if (program.open)... by Eljay on 01-31-2007 at 05:57 PM

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.
RE: if (program.open)... by mad_willsy on 01-31-2007 at 06:00 PM

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!
RE: if (program.open)... by Eljay on 01-31-2007 at 06:07 PM

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.


RE: if (program.open)... by mad_willsy on 01-31-2007 at 06:13 PM

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!