Just because I got bored:
Code
alias mywmi {
  .comopen wmi.open WbemScripting.SWbemLocator
  .comclose wmi.open $com(wmi.open,ConnectServer,1,bstr,.,bstr,root\CIMV2,dispatch* wmi.locator)
  set -l %properties Caption CommandLine CreationClassName CreationDate CSCreationClassName CSName Description ExecutablePath ExecutionState Handle HandleCount InstallDate KernelModeTime MaximumWorkingSetSize MinimumWorkingSetSize Name OSCreationClassName OSName OtherOperationCount OtherTransferCount PageFaults PageFileUsage ParentProcessId PeakPageFileUsage PeakVirtualSize PeakWorkingSetSize Priority PrivatePageCount ProcessId QuotaNonPagedPoolUsage QuotaPagedPoolUsage QuotaPeakNonPagedPoolUsage QuotaPeakPagedPoolUsage ReadOperationCount ReadTransferCount SessionId Status TerminationDate ThreadCount UserModeTime VirtualSize WindowsVersion WorkingSetSize WriteOperationCount WriteTransferCount
  .comclose wmi.locator $com(wmi.locator,ExecQuery,1,bstr,SELECT * FROM Win32_Process WHERE ExecutablePath=" $+ $replacex($mircexe,\,\\) $+ " AND CommandLine='" $+ $replacex($mircexe,\,\\) $+ " $cmdline $+ ',dispatch* wmi.properties) $com(wmi.properties,Count,3)
  set -l %instances $com(wmi.properties).result
  echo -a Retrieving $numtok(%properties,32) properties(s) from %instances instances from Win32_Process class in root\CIMV2 namespace
  set -l %x 1
  while (%x <= %instances) {
    tokenize 32 %properties
    while ($1) {
      echo -a Instance $+($chr(35),%x,:) $1 = $comval(wmi.properties,%x,$1)
      tokenize 32 $2-
    }
    inc %x
  }
  .comclose wmi.properties
  :error
  if ($error) {
    if ($com(wmi.open)) .comclose wmi.open
    if ($com(wmi.locator)) .comclose wmi.locator
    if ($com(wmi.properties)) .comclose wmi.properties
  }
}

It uses both ExecutablePath and CommandLine to get the right instance. Assuming each $cmdline is different, this should give the right answer each time.


I was also testing PID, and this is the easiest straight forward way to get the right one I could come up with:
Code
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
}

It uses CreationDate to figure out the right instance, but this will fail if the mIRC instances were started at the same exact time.