Hi Team,
I hope you are doing well. I got a blocker in my script, it is a custom script for signing out from Microsoft 365 application (Word, Excel, Powerpoint, Access, Outlook, Publisher, etc.). In this script, we are using the send-keys commands for automating the sign-out process for M365 apps from Desktop client machine only. NOTE: this signout is only machine not for Mobile M365 applications. I want to suppress the prompts when script execution is started. Please find the below:
function signoutofc {
function Send-Keys {
param(
[string]$keys,
[int]$sleepSeconds = 1
)
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.SendKeys]::SendWait($keys)
Start-Sleep -Seconds $sleepSeconds
}
$office365Path = "C:\Program Files (x86)\Microsoft Office\root\Office16\WINWORD.EXE"
$office2019Path = "C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE"
$office2016Path = "C:\Program Files (x86)\Microsoft Office\root\Office16\WINWORD.EXE"
$office365Path64 = "C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE"
$office2019Path64 = "C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE"
$office2016Path64 = "C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE"
$officeVersion = ""
$displayName = ""
try {
$office365 = Get-ItemProperty 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\O365ProPlusRetail*' -ErrorAction SilentlyContinue
$office2019 = Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\ProPlus2019Retail*' -ErrorAction SilentlyContinue
$office2016 = Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\PROPLUSRetail*' -ErrorAction SilentlyContinue
$officeWord = Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{90160000-008C-0000-0000-0000000FF1CE}*' -ErrorAction SilentlyContinue
if ($office365) {
$officeVersion = "Office365"
$displayName = $office365.DisplayName
} elseif ($office2019) {
$officeVersion = "Office2019"
$displayName = $office2019.DisplayName
} elseif ($office2016) {
$officeVersion = "Office2016"
$displayName = $office2016.DisplayName
} elseif ($officeWord) {
$officeVersion = "WordStandalone"
$displayName = $officeWord.DisplayName
} else {
$officeVersion = "Unknown"
$displayName = "Not Detected"
}
} catch {
}
if ($officeVersion -ne "") {
$officePath = ""
switch ($officeVersion) {
"Office365" {
if (Test-Path $office365Path) {
$officePath = $office365Path
} elseif (Test-Path $office365Path64) {
$officePath = $office365Path64
}
}
"Office2019" {
if (Test-Path $office2019Path) {
$officePath = $office2019Path
} elseif (Test-Path $office2019Path64) {
$officePath = $office2019Path64
}
}
"Office2016" {
if (Test-Path $office2016Path) {
$officePath = $office2016Path
} elseif (Test-Path $office2016Path64) {
$officePath = $office2016Path64
}
}
}
if ($officePath -ne "" -and (Test-Path $officePath)) {
Start-Process -FilePath $officePath -WindowStyle Hidden -ErrorAction SilentlyContinue
Start-Sleep -Seconds 1 -ErrorAction SilentlyContinue
Send-Keys '%L' -sleepSeconds 1 Hide
Send-Keys '%f' -sleepSeconds 1 Hide
Send-Keys 'D' -sleepSeconds 1 Hide
Send-Keys 'E' -sleepSeconds 1 Hide
if ($officeVersion -eq 'Office365') {
Send-Keys '{ENTER}' -sleepSeconds 1 Hide
} else {
Send-Keys '{Left}' -sleepSeconds 1 Hide
Send-Keys '{ENTER}' -sleepSeconds 0 Hide
}
Start-Sleep -Seconds 1 -ErrorAction SilentlyContinue
Stop-Process -Name WINWORD -Force -ErrorAction SilentlyContinue
}
}
}
signoutofc
If there is any other alternative, please suggest that as well also only for Desktop M365 solution.
Also, we tried removing the account from this registry- Computer\HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Common\Identity\Identities
did not helped. PLease help me to resolve this.