mIRC Home    About    Download    Register    News    Help

Print Thread
#230115 25/02/11 03:34 PM
Joined: Apr 2010
Posts: 969
F
Hoopy frood
OP Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
Currently I have an mSL script, writing the following vbscript, where $1- (the url) and %file are replaced within the script:
Code:
on error resume next

Set C = CreateObject("msxml2.xmlhttp.3.0")
if (err.number <> 0) then
  err.clear
  set C = CreateObject("msxml2.xmlhttp")
  if (err.number <> 0) then 
    err.clear
    set C = CreateObject("XMLHttpRequest")
    if (err.number <> 0) then wscript.quit(1)
  end if
end if

C.open "GET", $qt($1-) $+ , false
C.send 
if (err.number <> 0) then wscript.quit(2)

T = C.getResponseHeader("Content-Type")
if (T <> "") and (mid(T,1,6) <> "image/") then wscript.quit(3)  

set O = createobject("adodb.stream")
if (err.number <> 0) then wscript.quit(4)
O.type=1 
O.mode=3 
O.open 
O.write C.responsebody 
C.close
O.savetofile %file $+ ,2
if (err.number <> 0) then wscript.quit(5)
O.close


This script is then being executed from mIRC with the following where %s is the .vbs file:
Code:
.comopen %tvbs wscript.shell
if ($comerr) { goto error }
if ($comerr || !$com(%tvbs,run,1,bstr*,%s,uint,1,bool,true)) { goto error }
.remove %s

Now my question is: Is there a way to get the quit error code while still keeping the 'threading'?

Last edited by FroggieDaFrog; 25/02/11 04:10 PM.

I am SReject
My Stuff
Joined: Mar 2010
Posts: 57
W
Babel fish
Offline
Babel fish
W
Joined: Mar 2010
Posts: 57
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:

Code:
; 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:

Code:
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

Code:
alias pgmCallBack {
  var %com = $($ $+ $0, 2)

  ;rest of code will use %com instead of $1
}

Last edited by Wiz126; 26/02/11 02:29 AM.

Link Copied to Clipboard