mIRC Home    About    Download    Register    News    Help

Print Thread
$COM & WMI: getting all properties of a class #263392 23/07/18 11:47 PM
Joined: Dec 2015
Posts: 148
Dazuz Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Dec 2015
Posts: 148
How can I get all of the property names of a class without looking them up beforehand, or having to go through PowerShell.

After browsing the web for hours and hours, I've come to the conclusion that it can be done outside of mIRC. The problem is that no matter what I do, I fail to get the same results with mIRC. Something something something Properties_ something.

Code:
alias wmitest {
  .comopen locator WbemScripting.SWbemLocator
  .comclose locator $com(locator,ConnectServer,3,bstr,.,bstr,root\cimv2,dispatch* class)

  .comclose class $com(class,InstancesOf,3,bstr,Win32_OperatingSystem,dispatch* properties)
  ;.comclose class $com(class,ExecQuery,3,bstr,select * from Win32_OperatingSystem,dispatch* properties)

  var %x = $comval(properties,0,Properties_)
  echo -a Instances of Properties_: %x
  while (%x) {
    echo -a Instance %x $+ : $comval(properties,%x,Properties_)
    dec %x
  }

  .comclose properties
}

All I can get out of it is one instance of an integer that keeps changing.

I assume I'm missing something painfully obvious.

Re: $COM & WMI: getting all properties of a class [Re: Dazuz] #263393 24/07/18 02:13 AM
Joined: Jul 2006
Posts: 3,741
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,741
"Properties_" is a property of the SWbemObject object, you're not using that object.

Trying to use that object result in an error, I don't know if this is possible in mIRC, I doubt it.


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: $COM & WMI: getting all properties of a class [Re: Wims] #263394 24/07/18 06:45 AM
Joined: Dec 2015
Posts: 148
Dazuz Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Dec 2015
Posts: 148
Yeah, I tried that once, but it failed so fast that I just ignored it. I was hoping some kind of a miracle would happen, and it would work with SWbemLocator. Stupid I know, but the alternative wasn't any better.

Re: $COM & WMI: getting all properties of a class [Re: Dazuz] #263396 24/07/18 03:08 PM
Joined: Jul 2006
Posts: 3,741
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,741
I forgot.

You can write a vb/js/others? script which will do it, and then with mIRC you can connect to the shell and execute the vb/js code, you must be able to make a workaround with that smile


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: $COM & WMI: getting all properties of a class [Re: Wims] #263397 24/07/18 10:15 PM
Joined: Jul 2006
Posts: 3,741
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,741
After a big fight with vbs, I finally made it:

Code:
alias getmethod {
  .comopen getmethod MSScriptControl.ScriptControl
  if (!$comerr) {
    var -s %v $&
      strComputer = "." $lf $&
      strNameSpace = "root\cimv2" $lf $&
      strClass = $qt($1) $lf $&
      Set objClass = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\" & strNameSpace & ":" & strClass) $lf $&
      Set objFSO=CreateObject("Scripting.FileSystemObject") $lf $&
      Set objFile = objFSO.CreateTextFile( $qt($mircdirtempcom) ) $lf $&
      For Each objClassProperty In objClass.Properties_ $lf $&
      objFile.Write objClassProperty.Name & " " $lf $&
      Next $lf $&
      objFile.Close    


    noop $com(getmethod,Language,4,bstr,VBScript)
    if (!$comerr) noop $com(getmethod,ExecuteStatement,1,bstr,%v)
    if (!$comerr) {
      .comclose getmethod
      var %r $read(tempcom,tn,1)
      .remove tempcom
      return %r
    }
  }
  :error
  if ($error) reseterror
  if ($com(getmethod)) .comclose getmethod
}
//echo -a > $getmethod(Win32_OperatingSystem)
Quote:
> BootDevice BuildNumber BuildType Caption CodeSet CountryCode CreationClassName CSCreationClassName CSDVersion CSName CurrentTimeZone DataExecutionPrevention_32BitApplications DataExecutionPrevention_Available DataExecutionPrevention_Drivers DataExecutionPrevention_SupportPolicy Debug Description Distributed EncryptionLevel ForegroundApplicationBoost FreePhysicalMemory FreeSpaceInPagingFiles FreeVirtualMemory InstallDate LargeSystemCache LastBootUpTime LocalDateTime Locale Manufacturer MaxNumberOfProcesses MaxProcessMemorySize MUILanguages Name NumberOfLicensedUsers NumberOfProcesses NumberOfUsers OperatingSystemSKU Organization OSArchitecture OSLanguage OSProductSuite OSType OtherTypeDescription PAEEnabled PlusProductID PlusVersionNumber Primary ProductType RegisteredUser SerialNumber ServicePackMajorVersion ServicePackMinorVersion SizeStoredInPagingFiles Status SuiteMask SystemDevice SystemDirectory SystemDrive TotalSwapSpaceSize TotalVirtualMemorySize TotalVisibleMemorySize Version WindowsDirectory

Note that I worded everything in the script as though it was grabbing methods, but this is for the properties. If anyone want to get the method, just change objClass.Properties_ to objClass.Methods_


Edit: in my previous post I said it would be using the shell, I mixed things up there.


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: $COM & WMI: getting all properties of a class [Re: Wims] #263402 25/07/18 07:42 PM
Joined: Dec 2015
Posts: 148
Dazuz Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Dec 2015
Posts: 148
That's almost perfect!

I'm a visual basic newbie, but thanks to your lovely example, I was able to conjure up this one without the file part:
Code:
alias getmethod {
  .comopen getmethod MSScriptControl.ScriptControl
  if (!$comerr) {
    var -s %v $&
      strComputer = "." $lf $&
      strNameSpace = "root\cimv2" $lf $&
      strClass = $qt($1) $lf $&
      Set objClass = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\" & strNameSpace & ":" & strClass) $lf $&
      For Each objClassProperty In objClass.Properties_ $lf $&
      result = result & objClassProperty.Name & " " $lf $&
      Next

    noop $com(getmethod,Language,4,bstr,VBScript)
    if (!$comerr) noop $com(getmethod,ExecuteStatement,1,bstr,%v)
    if (!$comerr) noop $com(getmethod,eval,3,bstr*,result)
    if (!$comerr) {
      tokenize 1 $com(getmethod).result
      .comclose getmethod
      return $1
    }
  }
  :error
  if ($error) reseterror
  if ($com(getmethod)) .comclose getmethod
}


It's pretty damn close to what I wanted! Thanks!

Last edited by Dazuz; 25/07/18 07:50 PM. Reason: Corrected a brainfart.
Re: $COM & WMI: getting all properties of a class [Re: Dazuz] #263403 25/07/18 08:27 PM
Joined: Jul 2006
Posts: 3,741
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,741
Ah nice, i wrote to a file in case the result is too long for mIRC to handle.
Quote:
it's pretty damn close to what I wanted!
what's missing?


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: $COM & WMI: getting all properties of a class [Re: Wims] #263407 26/07/18 03:42 AM
Joined: Dec 2015
Posts: 148
Dazuz Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Dec 2015
Posts: 148
Well, it's unlikely to be too long with properties, but there's always binary variables.
Code:
if (!$comerr) return $com(getmethod,&x).result


It would have been nice to be able to access them directly without the VB middleman, although this way it probably works faster.

Re: $COM & WMI: getting all properties of a class [Re: Dazuz] #263420 26/07/18 09:57 PM
Joined: Jul 2006
Posts: 3,741
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,741
Using VB is not faster if we write to a file, your return variable usage is neat though. By 'close to what you wanted' are you referring to the usage of VB compared to mIRC doing all the job (if it were possible?)?


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: $COM & WMI: getting all properties of a class [Re: Wims] #263422 27/07/18 02:34 PM
Joined: Dec 2015
Posts: 148
Dazuz Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Dec 2015
Posts: 148
Yes, although using VB opens some doors, and now that I've been playing around with it for a while, it's actually quite nice.

For run, I made this little WMI exploration thing (which is basically just a crappier version of WMI Code Creator without the code creator part):
Code:
dialog -l wmie {
  title "WMI Exploration - /wmie"
  size -1 -1 545 340
  option dbu
  text "Looking up namespaces...", 10, 2 1 130 8
  list 11, 2 10 160 320, sort size
  text "Select a namespace", 20, 163 1 130 8
  list 21, 163 10 160 320, sort size
  text "Select a class", 30, 324 1 200 8
  list 31, 324 10 220 320, size
  check "Hide properties with $!null value", 32, 436 330 87 10
  edit "", 12, 2 330 160 10
  edit "", 22, 163 330 160 10
  edit "", 33, 324 330 109 10
  list 13, 1 340 10 10, hide size
  list 23, 163 340 10 10, hide size
  list 34, 324 340 10 10, hide size
}

alias wmie dialog $iif($dialog(wmie),-c,-m) wmie wmie

on *:dialog:wmie:*:*: {
  if ($devent == init) {
    .timerwmie.load -iom 1 1 wmie.namespaces
  }
  elseif ($devent == sclick) {
    if ($did == 11) && ($did(11).seltext) {
      var %x = 1,%v Set objClass = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\ $+ $did(11).seltext $+ ") $lf For Each objClassProperty In objClass.SubclassesOf() $lf result = result & objClassProperty.Path_.Class & $qt($chr(1)) $lf Next $lf
      if ($com(wmie.vb)) .comclose wmie.vb
      .comopen wmie.vb MSScriptControl.ScriptControl
      .comclose wmie.vb $com(wmie.vb,Language,4,bstr,VBScript) $com(wmie.vb,ExecuteStatement,1,bstr,%v) $com(wmie.vb,eval,3,bstr*,result) $com(wmie.vb,&x).result
      var %s = $did(21).seltext
      did -rh wmie 21,23
      while ($bfind(&x,%x,$chr(1))) {
        var %d = $bvar(&x,%x,$calc($v1 -%x)).text,%x $v1 + 1
        did -a wmie 23 %d
      }
      filter -ioc wmie 23 wmie 21 $+(*,$did(wmie,22),*)
      did -ra wmie 20 Classes ( $+ $bytes($did(21).lines,b) out of $bytes($did(23).lines,b) $+ ):
      did -v wmie 21
      if ($didwm(21,%s)) did -c wmie 21 $v1
      else {
        did -r wmie 31
        did -ra wmie 30 Select a class
      }
    }
    elseif ($did == 21) {
      var %v = Set objClass = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\ $+ $did(11).seltext $+ : $+ $did(21).seltext $+ ") $lf For Each objClassProperty In objClass.Properties_ $lf result = result & objClassProperty.Name & " " $lf Next
      if ($com(wmie.vb)) .comclose wmie.vb
      .comopen wmie.vb MSScriptControl.ScriptControl
      noop $com(wmie.vb,Language,4,bstr,VBScript) $com(wmie.vb,ExecuteStatement,1,bstr,%v) $com(wmie.vb,eval,3,bstr*,result)
      var %p = $com(wmie.vb).result
      .comclose wmie.vb
      if ($com(wmie.open)) .comclose wmie.open
      if ($com(wmie.locator)) .comclose wmie.locator
      if ($com(wmie.properties)) .comclose wmie.properties
      .comopen wmie.open WbemScripting.SWbemLocator
      .comclose wmie.open $com(wmie.open,ConnectServer,3,bstr,.,bstr,$did(11).seltext,dispatch* wmie.locator)
      noop $com(wmie.locator,InstancesOf,3,bstr,$did(21).seltext,dispatch* wmie.properties)
      noop $com(wmie.properties,Count,3)
      .comclose wmie.locator
      var %t = $iif($com(wmie.properties).result isnum,$v1,0),%x 1
      did -ra wmie 30 Properties $bytes($numtok(%p,32),b) properties in $bytes(%t,b) instance(s):
      did -rh wmie 31,34
      while (%x <= %t) && (%x <= 500) {
        did -a wmie 34 Instance $+($chr(35),%x,:)
        tokenize 32 %p
        while ($1) {
          did -a wmie 34 $1 = $comval(wmie.properties,%x,$1)
          tokenize 32 $2-
        }
        did -a wmie 34 $chr(160)
        inc %x
      }
      .comclose wmie.properties
      if ($did(32).state) filter -iocx wmie 34 wmie 31 * =
      else filter -ioc wmie 34 wmie 31 $+(*,$did(33),*)
      did -v wmie 31
    }
    elseif ($did == 32) {
      var %s = $did(31).seltext
      did -h wmie 31
      if ($did(32).state) filter -iocx wmie 31 wmie 31 * =
      else filter -ioc wmie 34 wmie 31 $+(*,$did(33),*)
      if ($didwm(31,%s)) did -c wmie 31 $v1
      did -v wmie 31
    }
  }
  elseif ($devent == dclick) && ($did($did).seltext) clipboard $v1
  elseif ($devent == edit) {
    if ($did == 12) {
      var %s = $did(11).seltext
      did -rh wmie 11
      filter -ioc wmie 13 wmie 11 $+(*,$did(12),*)
      did -ra wmie 10 Namespaces ( $+ $did(11).lines out of $did(13).lines $+ ):
      if ($didwm(11,%s)) did -c wmie 11 $v1
      else {
        did -r wmie 21,31
        did -ra wmie 20 Select a namespace
        did -ra wmie 30 Select a class
      }
      did -v wmie 11
    }
    elseif ($did == 22) {
      var %s = $did(21).seltext
      did -rh wmie 21
      filter -ioc wmie 23 wmie 21 $+(*,$did(22),*)
      did -ra wmie 20 Classes ( $+ $bytes($did(21).lines,b) out of $bytes($did(23).lines,b) $+ ):
      if ($didwm(21,%s)) did -c wmie 21 $v1
      else {
        did -r wmie 31
        did -ra wmie 30 Select a class
      }
      did -v wmie 21
    }
    elseif ($did == 33) {
      var %s = $did(31).seltext
      did -rh wmie 31
      filter -ioc wmie 34 wmie 31 $+(*,$did(33),*)
      if ($did(32).state) filter -iocx wmie 31 wmie 31 * =
      if ($didwm(31,%s)) did -c wmie 31 $v1
      did -v wmie 31
    }
  }
  elseif ($devent == close) {
    if ($com(wmie.vb)) .comclose wmie.vb
    if ($com(wmie.open)) .comclose wmie.open
    if ($com(wmie.locator)) .comclose wmie.locator
    if ($com(wmie.properties)) .comclose wmie.properties
    .timerwmie.* off
  }
}

alias -l wmie.namespaces {
  var %v = dim result $lf Call EnumNameSpaces("root") $lf Sub EnumNameSpaces(strNameSpace) $lf On Error Resume Next $lf result = result & " " & strNameSpace $lf Set objWMIService=GetObject("winmgmts:{impersonationLevel=impersonate}\\.\" & strNameSpace) $lf Set colNameSpaces = objWMIService.InstancesOf("__NAMESPACE") $lf For Each objNameSpace In colNameSpaces $lf Call EnumNameSpaces(strNameSpace & "\" & objNameSpace.Name) $lf Next $lf End Sub $lf
  if ($com(wmie.vb)) .comclose wmie.vb
  .comopen wmie.vb MSScriptControl.ScriptControl
  noop $com(wmie.vb,Language,4,bstr,VBScript) $com(wmie.vb,ExecuteStatement,3,bstr,%v) $com(wmie.vb,eval,3,bstr*,result)
  tokenize 32 $com(wmie.vb).result
  .comclose wmie.vb
  did -rh wmie 11,13
  did -a wmie 13 $*
  filter -ioc wmie 13 wmie 11 $+(*,$did(wmie,12),*)
  did -ra wmie 10 Namespaces ( $+ $did(wmie,11).lines out of $did(wmie,13).lines $+ ):
  did -v wmie 11
}

The startup takes a while, unless you're running mIRC in admin mode.

Re: $COM & WMI: getting all properties of a class [Re: Dazuz] #263423 27/07/18 03:00 PM
Joined: Jul 2006
Posts: 3,741
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,741
nice


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net