Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Tip: Analyzing Comobjects


  • 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.
$IE|Get-Member
You can try it yourself with "Shell.Application" as the ProgID.

Coco
  • Members
  • 697 posts
  • Last active: Oct 31 2015 07:26 PM
  • Joined: 27 Jul 2012

Thanks.... I use PowerShell a lot.... ;)



Menixator
  • Members
  • 744 posts
  • Last active: Sep 01 2015 02:54 PM
  • Joined: 10 Jul 2013

I use PowerShell a lot.... ;)

Me too! It's sooo much better than using the cmd. :D I mean it's features doesn't even start to compare with cmd!



KaoSDlanor
  • Members
  • 2 posts
  • Last active: Nov 08 2014 01:05 PM
  • Joined: 09 Dec 2013

when you said use the Get-Member cmdlet you followed it with an example, in that example there is a minor typo:

$IE|Get-Members

should be

$IE|Get-Member

but great tip :) thanks



Menixator
  • Members
  • 744 posts
  • Last active: Sep 01 2015 02:54 PM
  • Joined: 10 Jul 2013

Thanks for pointing it out, It's corrected now.  :)



mikek
  • Members
  • 161 posts
  • Last active: Nov 09 2015 05:02 PM
  • Joined: 21 Nov 2008

This is excellent. Thank you, Menixator. Just as an example to other readers, this is how the output looks:

 

MyPicture1_zpsf2942a50.jpg

 

MyPicture2_zps482c6d60.jpg

 

- Mike



mikek
  • Members
  • 161 posts
  • Last active: Nov 09 2015 05:02 PM
  • Joined: 21 Nov 2008

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:

 

dir  REGISTRY::HKEY_CLASSES_ROOT\CLSID -include PROGID -recurse | foreach {$_.GetValue("")} > progid_list.txt

 

http://blogs.msdn.co...Redirected=true

 

- Mike



mikek
  • Members
  • 161 posts
  • Last active: Nov 09 2015 05:02 PM
  • Joined: 21 Nov 2008

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?

 

Thank you.

 

MyPicture2_zps576d4d7f.jpg

 

- Mike



Menixator
  • Members
  • 744 posts
  • Last active: Sep 01 2015 02:54 PM
  • Joined: 10 Jul 2013

sorry, I can't really work on that because that COM object isn't registered on my pc.
here is what I get:

New-object : Retrieving the COM class factory for component with CLSID
{00000000-0000-0000-0000-000000000000} failed due to the following error: 80040154 Class not
registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
At line:1 char:15
+ $LMI = New-object -ComObject "LogMeIn.Systray"
+               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [New-Object], COMException
    + FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand


Jackie Sztuk _Blackholyman
  • Spam Officer
  • 3757 posts
  • Last active: Apr 03 2016 08:47 PM
  • Joined: 28 Feb 2012
Nice but just about the same thing can be done with Autohotkey

Spoiler


With this script you simply input the COM object to create and get the members and other info in a listview.

sd := ComObjCreate("shell.Explorer")
sd := ComObjCreate("Excel.Application")
sd := ComObjCreate("InternetExplorer.Application") example image:
2MgJVpQ.png

So no real need for powershell when looking for COM object info of this kind.
Helping%20you%20learn%20autohotkey.jpg?d

[AHK] Version. 1.1+ [CLOUD] DropBox ; Copy [WEBSITE] Blog ; About

lifeweaver
  • Members
  • 868 posts
  • Last active: Jan 25 2016 01:29 AM
  • Joined: 04 Mar 2013

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.


My script runs in A_AhkVersion:=1.1.22.07, get the latest version at http://ahkscript.org/download/

Check out this AutoHotkey tutorial: http://ahkscript.git...o/AHK_Tutorial/

Read the documentation: http://ahkscript.org.../AutoHotkey.htm


TLM
  • Administrators
  • 3864 posts
  • Last active:
  • Joined: 21 Aug 2006
Nice powershell.
Also excellent port, ty Blackholyman :)

Posted Image

don't duplicate, iterate!


MrGibbage
  • Members
  • 8 posts
  • Last active: Nov 07 2014 03:28 PM
  • Joined: 18 Nov 2009

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.



lifeweaver
  • Members
  • 868 posts
  • Last active: Jan 25 2016 01:29 AM
  • Joined: 04 Mar 2013

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.


My script runs in A_AhkVersion:=1.1.22.07, get the latest version at http://ahkscript.org/download/

Check out this AutoHotkey tutorial: http://ahkscript.git...o/AHK_Tutorial/

Read the documentation: http://ahkscript.org.../AutoHotkey.htm


jethrow
  • Moderators
  • 2854 posts
  • Last active:
  • Joined: 24 May 2009

... is there a way to use commands like this on a current web page that I have open in IE?

 

If you provide (part of) the web page name or url, it's fairly strait forward:

$name = '*name_part*'
$url = '*url_part*'

$wb = (New-Object -ComObject Shell.Application).Windows() |
    ?{ $_.LocationName -like $page -or $_.LocationULR -like $url }
$wb.document | get-member