mIRC Homepage
Posted By: Anonymous $com problem not getting result - 05/10/14 05:34 PM
hi,

I'm trying to convert this vbscript to mirc $com, and i cannot get the result.

Code:
Dim wmiQuery, objWMIService, objPing, objStatus
strHost = "google.com"
wmiQuery = "Select * From Win32_PingStatus Where Address = '" & strHost & "'"

Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set objPing = objWMIService.ExecQuery(wmiQuery)

For Each objStatus in objPing
    If IsNull(objStatus.StatusCode) Or objStatus.Statuscode<>0 Then
        ResolveIP = "Computer is Unreachable!"
    Else
        ResolveIP = objStatus.ProtocolAddress
    End If
Next

wscript.echo ResolveIp


I know i can use $com to eval vbscript and get the result, but my desire is to convert/translate into mirc scripting because now im trying to learn and trying to understand how $com working especially when vbs looping the object variable.

this is my converted code so far, but im not getting any result from it.

Code:
host2ip {
  :inittialize
  var %a $+(WbemScripting.SWbemLocator.,$ticks), %b $+(WbemScripting.SWbemLocator.,$calc($ticks + $r(11111,99999)))
  if ($com(%a)) goto inittialize
  .comopen %a WbemScripting.SWbemLocator
  echo -s Dispatch -> $com(%a,ConnectServer,3,dispatch* %b)
  .comclose %a 
  var %query SELECT * FROM Win32_PingStatus WHERE Address = $+(',$1,')
  if ($com(%b)) {
    echo Query -> $com(%b,ExecQuery,1,bstr*,%query,dispatch* %a)
    .comclose %b
  }
  %c = $comval(%a,0)
  echo Comval -> %c
  echo -s -> $comval(%a,0,ProtocolAddressResolved)
  .comclose %a
  if ($com(%b)) .comclose %b
}


I hope someone can help me understand more about $com.
Posted By: hixxy Re: $com problem not getting result - 05/10/14 07:41 PM
The 1 in your ExecQuery line should be a 3 because ExecQuery returns a result.

1 = call method
2 = property get
3 = call method + return result

Also you shouldn't be passing a string by reference there so bstr* should be bstr (no *).

Also $comval() uses a 1-based list not 0-based, so you'd need to use $comval() with a 1, not a 0, to get the first result.

Try those corrections and see if it works. If not I'll try and figure it out later when I've got access to a PC.
Posted By: Anonymous Re: $com problem not getting result - 06/10/14 07:12 AM
same with me, im outside right now. I'll once i get home
Posted By: Anonymous Re: $com problem not getting result - 06/10/14 04:42 PM
I have changed the code according to your post and the result is still not showing.

I have tried this way.
Code:
/host2ip google.com

;yahoo.com ip
/host2ip 98.138.253.109



Code:
host2ip {
  :inittialize
  var %a $+(WbemScripting.SWbemLocator.,$ticks), %b $+(WbemScripting.SWbemLocator.,$calc($ticks + $r(11111,99999)))
  if ($com(%a)) goto inittialize
  .comopen %a WbemScripting.SWbemLocator
  echo -s Dispatch -> $com(%a,ConnectServer,3,dispatch* %b)
  .comclose %a 
  var %query SELECT * FROM Win32_PingStatus WHERE Address = $+(',$1,')
  if ($com(%b)) {
    echo Query -> $com(%b,ExecQuery,3,bstr,%query,dispatch* %a)
    .comclose %b
  }
  %c = $comval(%a,0)
  echo Comval -> %c
  echo -s -> $comval(%a,1,ProtocolAddressResolved)
  .comclose %a
  if ($com(%b)) .comclose %b
}
Posted By: Anonymous Re: $com problem not getting result - 11/10/14 06:16 PM
i have tried many ways but still no luck.. some one help me please
© mIRC Discussion Forums