mIRC Homepage
Posted By: Dertikter $uptime - 13/09/05 11:38 PM
Is there anyway to make $uptime detect the uptime for other applications?
Example: $uptime(Notepad.exe,1) to see Notepad's uptime.

Note: Notepad is just an example.. :tongue:
Posted By: FiberOPtics Re: $uptime - 14/09/05 12:17 AM
/*

Usage: $proguptime(process [,N])

If no N is specified, it will take the first instance of the process that you specified.

Examples:

$proguptime(notepad.exe,2)
$proguptime(winamp.exe)

*/

Code:
alias proguptime {
  var %a = $$1 $+ $ticks, %b = b $+ %a
  .comopen %a WbemScripting.SWbemLocator
  if ($comerr) return 
  .comclose %a $com(%a,ConnectServer,1,dispatch* %b) 
  if ($com(%b)) .comclose %b $com(%b,ExecQuery,1,bstr*,SELECT $&
    creationdate FROM Win32_Process WHERE Name = " $+ $1",dispatch* %a)
  if (!$com(%a)) return 
  %b = $comval(%a,$iif($2 isnum 1-,$2,1),creationdate)
  .comclose %a
  return $iif(%b,$msdate(%b))
}

alias msdate {
  return $duration($calc($ctime - $ctime($+($left($$1,4),-,$mid($1,5,2),-, $&
    $mid($1,7,2) $mid($1,9,2),:,$mid($1,11,2),:,$mid($1,13,2)))))
}


Edit: forgot to mention, you need atleast mIRC 6.16 for this, and minimum Windows 2000 professional.
Posted By: Dertikter Re: $uptime - 14/09/05 01:34 AM
Thanks for the reply, however I have a problem.
* Invalid format: $com (line 12, script2.nns)
That error occurs, I have tested it on Windows XP Professional and Windows 2003 Server.

Is Windows 2000 Professional needed, or should it work on one of them?
Posted By: FiberOPtics Re: $uptime - 14/09/05 01:37 AM
The error you got is an mIRC error, unrelated to the OS you are using. It will work on any OS from win2k pro, that means XP and 2k3 as well.

I dare to guess that you didn't copy the code exactly as it looks on this forum to your mIRC, or that you are not using 6.16. Make sure you copy the code just the way it looks on the forum post.

You can do that by clicking on "Quote" on my post, and copy pasting the code there, as there is a problem with these forums and copying code. When pasting in the mIRC Scripts Editor, it tends to put everything on one line.

The code works fine for me, no errors.
Posted By: Dertikter Re: $uptime - 14/09/05 01:41 AM
Ah there we go, must've copied wrong after all.

Thanks for the help. smile
Posted By: Om3n Re: $uptime - 14/09/05 03:54 AM
How would you expand on this to find the total number of matching processes, and possibly for process to be wildcard matachable. I have no com call experience with mirc at all.

$proguptime(process [,N])

If N is 0 it could return the total number of matching processes. And if possible where process can include wildcards. ie $proguptime(pr?c*s.exe,1) will return the uptime for the first matching process, $proguptime(pr?c*s.exe,0) will return total number of matching processes. This way you could loop through the matches in cases where there are multiple sessions of a program running.
Posted By: r_alien Re: $uptime - 14/09/05 08:40 AM
I have tried to understand this code, but i have a splitting headache and can't do it frown

Here is what i have:

Code:
ON *:TEXT:*!uptime*:*: {
 var %ApacheUptime = $duration($proguptime(Apache.exe,1))
 /msg $chan Apache Uptime: $+ %ApacheUptime
}


But all i get is this:
Quote:
[18:34:04] alien-: !uptime
[18:34:06] hawk: Apache Uptime:
[18:35:12] alien-: !uptime
[18:35:14] hawk: Apache Uptime:
[18:35:51] alien-: !uptime
[18:35:53] hawk: Apache Uptime:
[18:37:12] alien-: !uptime
[18:37:14] hawk: Apache Uptime:
[18:38:21] alien-: !uptime
[18:38:22] hawk: Apache Uptime:


Any ideas?
Posted By: FiberOPtics Re: $uptime - 14/09/05 10:17 AM
If you looked closely at the code, you would notice that $msdate already returns a duration, so you should not use $duration($proguptime(apache.exe,1)) but just $proguptime(apache.exe).

To find out the exact name of the process, press ctrl+alt+del and go look in the Task Manager.


If you don't get any results, then it means either:

* You are not using this code on mIRC 6.16
* You are not using this code on an OS that is atleast Win2k professional.
* The process apache.exe is simply not running.
* You didn't copy the code properly from the message board to the scripts editor.
* Windows Scripting has been disabled on your computer (fex by an AVG like Norton), which means you cannot use any code with COM.

Posted By: FiberOPtics Re: $uptime - 14/09/05 11:06 AM
/*

Usage: $proguptime(name|wildcarded name [,N)[.name]

* Returns the uptime of the specified process.
* Process may contain wildcards * and ?
* The N will reference the Nth process. If N is 0 it returns the total number of matches.
* The property .name is optional, when used it will return a result in the form of "<name of process> <uptime>", which is handy when using wildcards to see which process it actually referenced.

Examples:

$proguptime(win*.ex?,1).name
$proguptime(notepad.exe,2)
$proguptime(*,0)

Minimum requirements:

mIRC 6.16
Windows 2000 Professional or higher

*/

Code:
alias proguptime {
  var %a = $$1 $+ $ticks, %b = b $+ %a, %c = creationdate,name
  .comopen %a WbemScripting.SWbemLocator
  if ($comerr) return COM Error
  .comclose %a $com(%a,ConnectServer,1,dispatch* %b) 
  if ($com(%b)) .comclose %b $com(%b,ExecQuery,1,bstr*,SELECT %c FROM $&amp;
    Win32_Process WHERE name LIKE $+(",$replace($1,*,%,?,_),"),dispatch* %a)
  if (!$com(%a)) return COM Error
  %c = $iif($prop == name,$comval(%a,$2,name))
  %b = $comval(%a,$iif($2 isnum 0-,$2,1),creationdate)
  .comclose %a
  if (%b) return $iif(!$2,%b,%c $msdate(%b))
}

alias msdate {
  return $duration($calc($ctime - $ctime($+($left($$1,4),-,$mid($1,5,2),-, $&amp;
    $mid($1,7,2) $mid($1,9,2),:,$mid($1,11,2),:,$mid($1,13,2)))))
}


Note that WMI is generally slow to perform queries, so I do not recommend calling this identifier too many times in a row to loop through it. One other possibly better way would be to do a query on all processes, add the entries to a hash table, and loop through that. Though, check how it performs with this code first and let me know how it goes. One other way would be that when you specify 0, that i return all matching processes along with their uptime in 1 string, so you can loop through that with $gettok or something.
Posted By: Om3n Re: $uptime - 14/09/05 02:04 PM
I recieve a com error, returned by the line: if (!$com(%a)) return COM Error
The examples in the mirc help file for com calls also fail to return correctly, i am using mirc 6.16 and win2k pro corp, and i have double checked that windows scripting is enabled on this machine. Any idea why this error occurs?
Posted By: FiberOPtics Re: $uptime - 14/09/05 02:48 PM
I have no idea. If none of the examples in the help file work, then it is most likely because of your system, unrelated to mIRC.

You wouldn't have by accident the option in mIRC enabled that disables "run, dll, and com commands" would ya? You can find this option by pressing alt+o -> Other -> Lock

Maybe you have an AVG that blocks all COM? I'm afraid I won't be able to help you with this matter.
Did you try the examples on a clean client (no scripts installed)? Any difference?

Let's do a small test, try this alias:

alias testvbs {
write test.vbs wscript.echo "this is a test"
run test.vbs
}

Tell me if you got a msgbox saying "This is a test".

If that works, then I can make some code in vbs for you and let that run from within mIRC. It's not the prettiest solution, but it's better than nothing.
Posted By: Om3n Re: $uptime - 14/09/05 04:50 PM
I have no avg on this pc, com calls are not disabled in mirc. And i should rephrase my comment about the examples in mirc help file, they do infact process to a point, but it seems whenever an if is used it returns false so the alias does not process fully. In the case of the 'drives' example it echo's the following, but the if $com(Services) and if $com(Instances) both return false.

* Opened Com 'Locator' (WbemScripting.SWbemLocator)
Com: 0
Result:
* Closed Com 'Locator'

The same seems to happen with the others (eg the /cpu example returns false for the if com services and more statements), so fails to return any useful information. The pattern here seems to be that any if $com(x) is false (likewise if !$com(x) is true) By removing the periods from your code i get this.

* Opened Com 'mirc.exe998556687' (WbemScripting.SWbemLocator)
* Closed Com 'mirc.exe998556687'
COM Error

So basically it at least reaches the comclose %a line, but must fail here with the $com() on the same line causing the if $com(%b) to be false and fail to call the proceding comclose and $com, which in return causes the if !$com(%a) to give the error. (at least this is best i can tell about where it goes wrong)

Dont go to any trouble with vbs, this thread mearly sparked an interest and an excuse to play with com objects through mirc. I read the tutorials i found on mircscripts.org and just wanted to experiment.

If i cant get it working on this pc its no big deal back to other projects.
Posted By: MikeChat Re: $uptime - 14/09/05 08:26 PM
I tried the updated code and got an error as well, untill I went back and removed the spaces between the lines.
Code:
alias proguptime {
  var %a = $$1 $+ $ticks, %b = b $+ %a, %c = creationdate,name
  .comopen %a WbemScripting.SWbemLocator
  if ($comerr) return COM Error
  .comclose %a $com(%a,ConnectServer,1,dispatch* %b) 
  if ($com(%b)) .comclose %b $com(%b,ExecQuery,1,bstr*,SELECT %c FROM $&amp;
    Win32_Process WHERE name LIKE $+(",$replace($1,*,%,?,_),"),dispatch* %a)
  if (!$com(%a)) return COM Error
  %c = $iif($prop == name,$comval(%a,$2,name))
  %b = $comval(%a,$iif($2 isnum 0-,$2,1),creationdate)
  .comclose %a
  if (%b) return $iif(!$2,%b,%c $msdate(%b))
}

alias msdate {
  return $duration($calc($ctime - $ctime($+($left($$1,4),-,$mid($1,5,2),-, $&amp;
    $mid($1,7,2) $mid($1,9,2),:,$mid($1,11,2),:,$mid($1,13,2)))))
}

also note the one line is split with the $& you might try removing that and having that all one line
Posted By: FiberOPtics Re: $uptime - 14/09/05 09:06 PM
Oh my...

I know what's the problem, when you edit your code, a lot of people who use firefox fex see the code with spaces in between, and that does in fact screw up code that uses $&.

It never looks like it has spaces in between lines for me (what you posted looks exactly like my post for me), but I remember that a lot do see it like that after the author has edited his code. Second time this screws up a snippet of mine.

Damnit.

EDIT: I have checked, it indeed shows the code with spaces in between lines when viewing with firefox, this does not happen with Internet explorer! Grrrrrr.... this is the last time I use code tags, even though they make the code easier to read because of the indent.
Posted By: DaveC Re: $uptime - 14/09/05 10:45 PM
You could just stop using $& I always thought using them to space code out to multiple lines was a bit risky.
Posted By: MikeChat Re: $uptime - 14/09/05 11:14 PM
I have only noticed the extra line breaks on here after an edit.
so its something the board's coding does.
Posted By: FiberOPtics Re: $uptime - 15/09/05 01:02 AM
I do it because i find it highly annoying when code from a post causes the entire thread to be stretched out. If this bug with the code tags wouldn't exist there wouldn't be an issue, but unfortunately...
Posted By: Om3n Re: $uptime - 15/09/05 02:35 AM
The problem is something with my system not a code copying issue, i use ie and the first thing i did when it failed was make sure there were not any any spacing issues, remove the $&'s and remove the periods from the comopen/comclose so i could see where it was going. It's definately some bigger issue on my system because its not restricted to just this code or the examples in the help file. It is probable there is some issue with the windows scripting engine not functioning correctly even when enabled that i am not sure how to fix.
Posted By: Riamus2 Re: $uptime - 15/09/05 12:51 PM
Or tell Firefox to get it together and make a browser that doesn't do that. laugh

Tell them the problem while they're still in beta on 1.5 and see if they can have it fixed by the final release of 1.5.
Posted By: hixxy Re: $uptime - 15/09/05 04:12 PM
The html is displayed correctly in firefox. It is, in fact, internet explorer that displays the html incorrectly (which is why you don't see a forum/code tag bug in ie). That would make the problem an ie bug, not a firefox one.

Edit: see this thread.
© mIRC Discussion Forums