PowerShell – COM Programming – App – Word.Application – Day 01

 

Outline

  1. Determine the Application ID for the Application’s Com Object
    • Example
      • Microsoft Office
        • Microsoft Word => Word.Application
  2. Issue [type]::GetTypeFromProgID against Application ID
  3. Issue [Activator]::CreateInstance against the retrieved type
  4. Retrieve the follow Object’s Property
    • Version
    • Build
    • BuildFull
    • Path

 

Code

PowerShell



Set-StrictMode -Version 1.0

[string] $appID="";
[string] $log="";
[string] $logFormat="";

$logFormat = "`t{0} => {1}"

$appID="Word.Application";

$objType = [type]::GetTypeFromProgID($appID);

if ($objType -ne $null)
{

    Write-Host

    $log = $logFormat -f "AppName", $objType
    Write-Host $log

    $objApp = [Activator]::CreateInstance($objType)

    if ($objApp -ne $null)
    {
        #$objApp

        #$objApp | Get-Member

        $log = $logFormat -f "Name", $objApp.Name
        Write-Host $log

        $log = $logFormat -f "Application", $objApp.Application
        Write-Host $log

        $log = $logFormat -f "Version", $objApp.Version
        Write-Host $log

        $log = $logFormat -f "Build", $objApp.Build
        Write-Host $log

        $log = $logFormat -f "BuildFull", $objApp.BuildFull
        Write-Host $log

        $log = $logFormat -f "Path", $objApp.Path
        Write-Host $log

        $objApp = $null

    } # if ($objApp -ne $null)

} # if ($objType -ne $null)
    <span id="mce_SELREST_start" style="overflow:hidden;line-height:0;">&#65279;</span>

Output

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s