Last active
July 16, 2019 12:15
-
-
Save u1735067/283264bb4b74e5d6573fd89dae772ef6 to your computer and use it in GitHub Desktop.
Powershell scriptlet to allow dedicated Excel instances
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ErrorActionPreference = "Stop" | |
# https://blogs.technet.microsoft.com/heyscriptingguy/2013/12/10/use-powershell-to-create-registry-keys/ | |
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/set-itemproperty | |
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/set-item | |
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/remove-item | |
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-itempropertyvalue | |
# https://docs.microsoft.com/en-us/windows/desktop/shell/fa-verbs | |
# https://docs.microsoft.com/en-us/windows/desktop/shell/handlers | |
# https://docs.microsoft.com/en-us/windows/desktop/shell/fa-sample-scenarios | |
# http://www.angelfire.com/biz/rhaminisys/fileasoc.html | |
# https://social.technet.microsoft.com/wiki/contents/articles/4542.powershell-loops.aspx | |
# https://ss64.com/ps/syntax-arrays.html | |
# https://docs.microsoft.com/fr-fr/powershell/module/Microsoft.PowerShell.Utility/write-host | |
# https://stackoverflow.com/questions/9948517/how-to-stop-a-powershell-script-on-the-first-error | |
# https://www.powershellgallery.com/packages/PSLDAPQueryLogging/1.0/Content/Private%5CGet-RegValue.ps1 | |
# https://stackoverflow.com/questions/18000757/regex-match-any-string-powershell | |
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-childitem?view=powershell-6 | |
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/test-path?view=powershell-6 | |
# https://stackoverflow.com/questions/13466698/find-values-in-registry-subkeys-and-delete-them | |
# https://stackoverflow.com/questions/11474449/get-childitem-trying-to-get-the-registry-entry-from-current-working-directory | |
# https://www.itprotoday.com/powershell/powershell-basics-filtering-objects | |
# https://stackoverflow.com/questions/14406315/how-to-get-an-objects-propertys-value-by-property-name-in-powershell | |
# https://stackoverflow.com/questions/11471519/how-to-get-registrykey-name-alone-instead-of-full-registry-keypath | |
(Get-ChildItem HKLM:\Software\Classes\ -Name) -match '^Excel\..*' | ForEach-Object { | |
$open_path = "HKLM:\Software\Classes\${_}\shell\Open" | |
if (Test-Path "${open_path}\command") { | |
$current_command = Get-ItemPropertyValue -Path "${open_path}\command" -Name '(Default)' | |
if ($current_command -match "\\excel\.exe.+/dde$") { | |
$new_command = $current_command -Replace '/dde$','"%1"' | |
Write-Output "${_}: Backuping keys (command, ddeexec)" | |
Rename-Item -Path "${open_path}\ddeexec" -NewName 'ddeexec.backup' | |
Rename-Item -Path "${open_path}\command" -NewName 'command.backup' | |
Write-Output "${_}: Writing new command" | |
New-Item -Path "${open_path}\command" -Value $new_command | Out-Null | |
} | |
} | |
} | |
#Get-ItemPropertyValue -Path "HKLM:\Software\Classes\$_\shell\Open\command" -Name '(Default)' | |
#} | |
#Get-Item HKLM:\Software\Classes\Excel.* | % { $_.Name } | |
#Get-Item HKLM:\Software\Classes\Excel.* | ForEach-Object { | |
# Get-ItemPropertyValue -Path "HKLM:\Software\Classes\$_.Name\shell\Open\command" -Name '(Default)' | |
#} | |
#Set-Item -Path "HKLM:\Software\Classes\${class}\shell\Open\command" -value '"C:\Program Files\Microsoft Office\Office14\EXCEL.EXE" "%1"' | |
#New-Item -Path "HKLM:\Software\Classes\${class}\shell\Open\command" -value '"C:\Program Files\Microsoft Office\Office14\EXCEL.EXE" "%1"' >$null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ErrorActionPreference = "Stop" | |
(Get-ChildItem HKLM:\Software\Classes\ -Name) -match '^Excel\..*' | ForEach-Object { | |
$open_path = "HKLM:\Software\Classes\${_}\shell\Open" | |
# If there's a full backup, then restore | |
if ((Test-Path "${open_path}\command.backup") -And (Test-Path "${open_path}\ddeexec.backup")) { | |
Write-Output "${_}: Deleting new command" | |
Remove-Item "${open_path}\command" | |
Write-Output "${_}: Restoring keys (command, ddeexec)" | |
Rename-Item -Path "${open_path}\ddeexec.backup" -NewName 'ddeexec' | |
Rename-Item -Path "${open_path}\command.backup" -NewName 'command' | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment