Enumerate the methods and properties exposed by a COM object given the ProgID

1.3k views Asked by At

Following this question, I want to list all the methods and properties exposed by a Component Object Model (COM) object, given its ProgID. From here I can list all the COM object ProgIDs available from the registry:

dir  REGISTRY::HKEY_CLASSES_ROOT\CLSID -include PROGID -recurse | foreach {$_.GetValue(“”)}

though it adds some numbers (e.g., .1) at the end of some exported strings.

And here proposes a small script that does the job given the CLSID. Pseudocode:

[activator]::CreateInstance([type]::GetTypeFromCLSID($CLSID)) | Get-Member

One caveat, I don't know PowerShell and the above oneliner is most probably wrong.

I would appreciate it if you could help me know how I can get the list of methods and properties of a COM object knowing its ProgID (e.g., WScript.Shell), using the above snippets or any other way.

P.S. It doesn't have to be necessarily a PowerShell solution. cmd/batch, JScript, and VBScript solutions are also appreciated.

1

There are 1 answers

2
CFou On BEST ANSWER

Public methods and properties are exposed if you instanciate an object from the COM Object

New-Object -ComObject WScript.Shell | Get-Member

will return

Name                     MemberType            Definition                                   
----                     ----------            ----------                                   
AppActivate              Method                bool AppActivate (Variant, Variant)          
CreateShortcut           Method                IDispatch CreateShortcut (string)            
Exec                     Method                IWshExec Exec (string)                       
ExpandEnvironmentStrings Method                string ExpandEnvironmentStrings (string)     
LogEvent                 Method                bool LogEvent (Variant, string, string)      
Popup                    Method                int Popup (string, Variant, Variant, Variant)
RegDelete                Method                void RegDelete (string)                      
RegRead                  Method                Variant RegRead (string)                     
RegWrite                 Method                void RegWrite (string, Variant, Variant)     
Run                      Method                int Run (string, Variant, Variant)           
SendKeys                 Method                void SendKeys (string, Variant)              
Environment              ParameterizedProperty IWshEnvironment Environment (Variant) {get}  
CurrentDirectory         Property              string CurrentDirectory () {get} {set}       
SpecialFolders           Property              IWshCollection SpecialFolders () {get}

The @Simon Mourrier strategy will work fine too