Advertisement
guyrleech

Find "interesting" COM object types

Jan 16th, 2023 (edited)
790
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ## Try and create instances of all COM object types we find.
  2. ## The Get-Member count greater than 6 tries to exclude com objects which don't seem useful as they only have the default methods which total 6
  3.  
  4. Get-CimInstance -ClassName Win32_COMSetting | where-object { $_.PSObject.Properties[ 'versionindependentprogid' ] -and $_.versionindependentprogid -match '.+' } | ForEach-Object { $class = $_ ; try { if( $null -ne ($object = New-Object -ComObject $_.versionindependentprogid -ErrorAction SilentlyContinue) -and ($members = @( $object|Get-Member -ErrorAction SilentlyContinue )) -and $members.Count -gt 6 ) { [pscustomobject]@{ Progid = $_.versionindependentprogid ; Caption = $_.Caption ; Members = $members } } } catch { Write-Warning "$($class.versionindependentprogid) failed" } }
  5.  
  6. ## With server and vendor name and will only try and create an object of a given type once so doesn't more than one try where multiple versions available
  7.  
  8. $progIds=@{};Get-CimInstance -ClassName Win32_COMSetting | where-object { $_.PSObject.Properties[ 'versionindependentprogid' ] -and $_.versionindependentprogid -match '.+' } | ForEach-Object { $class = $_ ; if( -Not $progIds.ContainsKey( $_.versionindependentprogid )) { try { $progids.Add( $_.versionindependentprogid , 1 ) ; if( $null -ne ($object = New-Object -ComObject $_.versionindependentprogid -ErrorAction SilentlyContinue) -and ($members = @( $object|Get-Member -EA 0)) -and $members.Count -gt 6 ) { if( ( $provider = $_.LocalServer32 ) -or ( $provider = $_.InprocServer32 ) ) { $provider = ([System.Environment]::ExpandEnvironmentVariables( $provider ) -replace '\s*/.*$').Trim('"') } ; [pscustomobject]@{ Progid = $_.versionindependentprogid ; Caption = $_.Caption ; Provider = $provider ; Vendor = gp -Path $provider -EA 0 | Select -Expand VersionInfo -EA 0 |Select -Expand CompanyName -EA 0; Members = (($members|select @{n='member';e={ if( $_.MemberType -ieq 'Method' ) { "$($_.Name)()" } else { $_.Name } }}) | Select -expand member )} } } catch { Write-Warning "$($class.versionindependentprogid) failed : $_" }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement