mIRC Home    About    Download    Register    News    Help

Print Thread
#270099 30/03/22 12:15 PM
Joined: Jul 2006
Posts: 4,150
W
Wims Offline OP
Hoopy frood
OP Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,150
I'd like to see a new identifier $mircpid which would return the processus ID of the executable currently running.

In addition, here is an attempt at scripting $mircpid by Dazuz:

Originally Posted by https://forums.mirc.com/ubbthreads.php/ubb/showflat/Number/268212/
alias pid {
tokenize 1 $ctime
while ($1 == $ctime) noop
.comopen wmi.open WbemScripting.SWbemLocator
.comclose wmi.open $com(wmi.open,ConnectServer,1,bstr,.,bstr,root\CIMV2,dispatch* wmi.locator)
.comclose wmi.locator $com(wmi.locator,ExecQuery,1,bstr,SELECT * FROM Win32_Process WHERE ExecutablePath = " $+ $replacex($mircexe,\,\\) $+ ",dispatch* wmi.properties) $com(wmi.properties,Count,3)
set -l %d $asctime($floor($calc($ctime -($uptime(mirc)/1000))),yyyymmddHHnnss)
set -l %x 1
set -l %pid
while (%x <= $com(wmi.properties).result) {
if (%d $+ .* iswm $comval(wmi.properties,%x,CreationDate)) %pid = $comval(wmi.properties,%x,ProcessId)
inc %x
}
.comclose wmi.properties
return %pid
:error
if ($com(wmi.open)) .comclose wmi.open
if ($com(wmi.locator)) .comclose wmi.locator
if ($com(wmi.properties)) .comclose wmi.properties
}
This alias may work, but it will fail 'most of the time', with more failures as the mirc uptime gets bigger (depending on the activity). What's interesting is that it convert the mirc uptime to an $asctime format going from years to second and compare that with the CreationDate of executables matching the name $mircexe.
If you try immediately after a reboot of mirc, it will typically work, but not after running mirc for a while.
The creation date and the mirc uptime should be the exact same second to me, maybe a couple of milliseconds apart, but my drift was 12 secs when i tried initially, with an uptime of 2 weeks.
I do not understand how the values used here, $ctime, $uptime, can drift from the creationData over time, even if mIRC freezes for 12 seconds from a while loop, the value should not drift like that imo, I'm a bit curious how it can happen.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #270115 03/04/22 08:21 AM
Joined: Feb 2015
Posts: 138
kap Offline
Vogon poet
Offline
Vogon poet
Joined: Feb 2015
Posts: 138
I would like to add my support asking for a $pid identifier smile


GNU Terry Pratchett - Looking for a mIRC help channel -> Check #mircscripting @ irc.swiftirc.net

Link Copied to Clipboard