Skip to content

Instantly share code, notes, and snippets.

@afreeland
Created August 23, 2016 14:44
Show Gist options
  • Save afreeland/781007697ac7489e50603284a7f1e337 to your computer and use it in GitHub Desktop.
Save afreeland/781007697ac7489e50603284a7f1e337 to your computer and use it in GitHub Desktop.
PowerShell: Excel Multiple Windows
$path = @("Registry::HKCR\Excel.Sheet.12","Registry::HKCR\Excel.Sheet.8")
foreach ($item in $path) {
# Path to Excel Shell
$registryPath = "$($item)\shell\Open\command"
$ddExecPath = "$($item)\shell\Open\ddeexec"
# Get our current value for the (default) property
$val = (Get-ItemProperty -Path $registryPath -Name "(Default)")."(default)"
Write-Host $val
# Test if it contains a "%1"
if( $val.Contains("%1") ){
Write-Host "(Default) property already contains `"%1`" "
}else{
Write-Host "Updating $($registryPath)\(Default) to include `"%1`" "
$val = $val + " `"%1`""
Write-Host $val
New-ItemProperty -Path $registryPath -Name "(Default)" -Value $val -Force | Out-Null
Write-Host "Modification complete"
}
function Test-RegistryProperty{
param (
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]$Path,
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]$Property
)
try {
Get-ItemProperty -Path $Path | Select-Object -ExpandProperty $Property -ErrorAction Stop | Out-Null
return $true
}catch {
return $false
}
}
# We need to test our path for the "command" key
if(Test-RegistryProperty -Path $registryPath -Property "command"){
Write-Host "The `"command`" key exists"
Rename-ItemProperty -Path $registryPath -Name "command" -NewName "command2"
Write-Host "Property updated command => command2"
}else{
Write-Host "The `"command`" key does NOT exist"
}
# We need to rename the "ddeexec" key
if(Test-Path $ddExecPath)
{
Write-Host "Updating `"ddeexec`" "
Rename-Item -Path $ddExecPath -NewName "ddeexec2"
Write-Host "Key updated ddeexec => ddeexec2 "
}else{
Write-Host "ddexec does not exist (may already of been changed)"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment