mIRC Home    About    Download    Register    News    Help

Print Thread
#130173 13/09/05 11:38 PM
Joined: Nov 2004
Posts: 21
D
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Nov 2004
Posts: 21
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:

#130174 14/09/05 12:17 AM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
/*

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.


Gone.
#130175 14/09/05 01:34 AM
Joined: Nov 2004
Posts: 21
D
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Nov 2004
Posts: 21
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?

#130176 14/09/05 01:37 AM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
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.


Gone.
#130177 14/09/05 01:41 AM
Joined: Nov 2004
Posts: 21
D
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Nov 2004
Posts: 21
Ah there we go, must've copied wrong after all.

Thanks for the help. smile

#130178 14/09/05 03:54 AM
Joined: Jul 2003
Posts: 655
Fjord artisan
Offline
Fjord artisan
Joined: Jul 2003
Posts: 655
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.

Last edited by Om3n; 14/09/05 04:00 AM.

"Allen is having a small problem and needs help adjusting his attitude" - Flutterby
#130179 14/09/05 08:40 AM
Joined: Aug 2005
Posts: 32
R
Ameglian cow
Offline
Ameglian cow
R
Joined: Aug 2005
Posts: 32
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?

#130180 14/09/05 10:17 AM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
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.



Gone.
#130181 14/09/05 11:06 AM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
/*

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.


Gone.
#130182 14/09/05 02:04 PM
Joined: Jul 2003
Posts: 655
Fjord artisan
Offline
Fjord artisan
Joined: Jul 2003
Posts: 655
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?


"Allen is having a small problem and needs help adjusting his attitude" - Flutterby
#130183 14/09/05 02:48 PM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
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.


Gone.
#130184 14/09/05 04:50 PM
Joined: Jul 2003
Posts: 655
Fjord artisan
Offline
Fjord artisan
Joined: Jul 2003
Posts: 655
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.


"Allen is having a small problem and needs help adjusting his attitude" - Flutterby
#130185 14/09/05 08:26 PM
Joined: Dec 2002
Posts: 1,245
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
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

#130186 14/09/05 09:06 PM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
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.


Gone.
#130187 14/09/05 10:45 PM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
You could just stop using $& I always thought using them to space code out to multiple lines was a bit risky.

#130188 14/09/05 11:14 PM
Joined: Dec 2002
Posts: 1,245
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
I have only noticed the extra line breaks on here after an edit.
so its something the board's coding does.

#130189 15/09/05 01:02 AM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
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...


Gone.
#130190 15/09/05 02:35 AM
Joined: Jul 2003
Posts: 655
Fjord artisan
Offline
Fjord artisan
Joined: Jul 2003
Posts: 655
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.


"Allen is having a small problem and needs help adjusting his attitude" - Flutterby
#130191 15/09/05 12:51 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
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.


Invision Support
#Invision on irc.irchighway.net
#130192 15/09/05 04:12 PM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
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.

Last edited by hixxy; 15/09/05 04:16 PM.

Link Copied to Clipboard