Ok, to get the return value, we have to make sure the program has already ended. This inheritly means that $com is not suitable for the job. Using $com you will not get the desirable result, in most cases you will probably get a bogus 0 result. Instead, you will have to use comcall, and have a call-back routine execute when the program is done running and has returned its value. This will allow the script to run and not freeze up mIRC as well.
Particle Example:
; main method running your vbs script
alias runVbs {
var %s = $mircdir $+ foo.vbs
var %tvbs = x
.comopen %tvbs WScript.Shell
if (!$comcall(%tvbs, pgmCallBack, Run, 1, bstr*, %s, int, 1, bool, 1)) {
comerr %tvbs
}
}
; our callback routine that executes when the program is done
alias pgmCallBack {
if ($comerr) { comerr $1 | return }
echo -a return code: $com($1).result
.comclose $1
}
; some error handling
alias comerr {
echo -a Com $qt($1) Error: $com($1).error - $com($1).errortext
.comclose $1
}
So, if your vbscript executed "Wscript.Quit 12", the return value will be 12.
Edit: just a little more information replying from IRC, yes, you can pass parameters to the callback routine by simply specifying it inside the $comcall after the alias name:
for example:
if (!$comcall(%tvbs, pgmCallBack AA BBB CCC DDDD, Run, 1, bstr*, %s, int, 1, bool, 1)) {
comerr %tvbs
}
this also means the callback routine has to be adjusted accordingly
alias pgmCallBack {
var %com = $($ $+ $0, 2)
;rest of code will use %com instead of $1
}