You currently have javascript disabled. Several functions may not work. Please re-enable javascript to access full functionality.

Tip: Analyzing Comobjects

Started by
Menixator
, Nov 16 2013 06:10 AM

Please log in to reply

14 replies to this topic

Menixator

Members

744 posts

Last active: Sep 01 2015 02:54 PM

Joined: 10 Jul 2013

When you are working with COM objects, you might want to find out what methods are available.Then, you'd probably search for a documentation.But what you don't realize is, you don't really need to search the internet for them! You can just use powershell to find them! It's really simple:

First, Open powershell.Then create the object. The syntax is:

$variable = New-object -ComObject "ProgID"

Example:

$IE = New-object -ComObject "InternetExplorer.Application"

Then, you could just type in the variable containing the object to see it's current properties.

$IE

To see it's available properties and methods, you can use the Get-Member cmdlet.

This example worked great as described. Without knowing to plug in "InternetExplorer.Application" as the parameter for the New-object command, how would I bring up a list of available applications that are supported?

EDIT: I didn't think I would find anything but after google searching, this is the command:

Ok, so when I list the available ProgID names I see "InternetExplorer.Application.1" listed. Based on this I assume the ".1" can be removed. I also see "LogMeIn.Systray.1" and "LogMeIn.GuestInvite.1". I would like to see their available COM options, but when I type "$LMI = New-object -ComObject "LogMeIn.Systray" (and also the same command with ".1"), I get an error. Does anyone know why these errors appear and what they mean?

Nice I've saw mentionings of the iTypeInfo but couldn't figure it out, if all you want to look at is the methods this is nice. However I would say PowerShell is still better in that you can test it dynamically, you have a console you can continue to type code into, I really wish AutoHotkey had something like the ruby irb!

For example you can do

;create object

; Get-Member on that object

; Then Get-Member on a method or property of that object, then Get-Member on a method or property of that method or property etc.

What if I wanted to find out what methods and properties were available to the document property of the $IE InterenetExplorer.Application object? I tried things like $IE.Document|Get-Member but it throws an error. Also, is there a way to use commands like this on a current web page that I have open in IE? It would be great for testing this way to find out if commands will work before sticking them into AHK.

You need to navigate to a page before calling Get-Member on the Document property, something like '$ie.navigate("http://www.google.com")' then you can do '$ie.Document|gm'. There is a way to use similar commands in most browsers, you need to access their 'console', for IE you can hit F12 to open the developer tools, go to the console, then type something like 'document.getElementById' or something, note in my version of IE after I type 'document.' a list of possible commands is shown.