Можно ли запланировать режим «только сигналы» в windows 10 с помощью shell-скрипта

There’s a PowerShell workaround which revolves around clicking menu entries:

Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.SendKeys]::SendWait("(^{ESC})")
Start-Sleep -Milliseconds 500
[System.Windows.Forms.SendKeys]::SendWait("(Focus Assist)")
Start-Sleep -Milliseconds 200
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
Start-Sleep -Milliseconds 500
[System.Windows.Forms.SendKeys]::SendWait("{TAB}{TAB}{TAB}{TAB}{TAB}")
Start-Sleep -Milliseconds 500
[System.Windows.Forms.SendKeys]::SendWait("(%{F4})")

Source. This basically opens Start menu, searches Focus Assist, opens settings for it, goes to proper field with Tab, marks the radio with Space and closes the window.

Of course it might not work if you’re doing something else at that time and interrupt it, PowerShell is not the best tool for GUI automation.

And alternatively you can automate Win + A instead, which opens the actions center with a tile which can be switched to Alarms only.

@SQLDBAWithABeard


  • You must be signed in to star a gist


  • You must be signed in to fork a gist



  • Save SQLDBAWithABeard/ab2dd8c60bb8453aac88d981eb8321c6 to your computer and use it in GitHub Desktop.



Save SQLDBAWithABeard/ab2dd8c60bb8453aac88d981eb8321c6 to your computer and use it in GitHub Desktop.

Focus Assist change with powershell hack

Focus Assist Off
AssemblyName System.Windows.Forms
[]::SendWait()
Milliseconds
[]::SendWait()
Milliseconds
[]::SendWait()
Milliseconds
[]::SendWait()
Milliseconds
[]::SendWait()
Focus Assist Priority
AssemblyName System.Windows.Forms
[]::SendWait()
Milliseconds
[]::SendWait()
Milliseconds
[]::SendWait()
Milliseconds
[]::SendWait()
Milliseconds
[]::SendWait()
Focus Assist Alarms
AssemblyName System.Windows.Forms
[]::SendWait()
Milliseconds
[]::SendWait()
Milliseconds
[]::SendWait()
Milliseconds
[]::SendWait()
Milliseconds
[]::SendWait()

So far, the script works around half of the time. There have been issues where windows don’t open correctly and it doesn’t get named right, or it skips over a key or two, leading to undesired results. I have tried the Word module but have had no success. I need this to work, essentially, 100% of the time because it’ll be automating the task.

Are there any recommendations on how to lessen the fail rate other than boosting the time between SendKeys calls? I’m open to using any modules to complete this task.

Script (for reference):

$date = Get-Date -Format "MM-dd-yyyy"
Start-Process -Filepath 'C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE' '\\kfs\users\L93563\mailMergePap.docx'
## ------------------------------------------------------------------------------
Add-Type -AssemblyName Microsoft.VisualBasic
Add-Type -AssemblyName System.Windows.Forms
[Microsoft.VisualBasic.Interaction]::AppActivate('Word')
Start-Sleep -Milliseconds 2000
[System.Windows.Forms.SendKeys]::SendWait("{LEFT}")
Start-Sleep -Milliseconds 250
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
Start-Sleep -Milliseconds 2000
[System.Windows.Forms.SendKeys]::SendWait("%")
Start-Sleep -Milliseconds 1000
[System.Windows.Forms.SendKeys]::SendWait("MRE")
Start-Sleep -Milliseconds 2000
[System.Windows.Forms.SendKeys]::SendWait("cql.lacny.com SMB NegPap.odc {ENTER}{ENTER}")
Start-Sleep -Milliseconds 100
[System.Windows.Forms.SendKeys]::SendWait("%")
Start-Sleep -Milliseconds 250
[System.Windows.Forms.SendKeys]::SendWait("M")
Start-Sleep -Milliseconds 250
[System.Windows.Forms.SendKeys]::SendWait("F")
Start-Sleep -Milliseconds 250
[System.Windows.Forms.SendKeys]::SendWait("E")
Start-Sleep -Milliseconds 250
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
Start-Sleep -Milliseconds 500
[System.Windows.Forms.SendKeys]::SendWait("%")
Start-Sleep -Milliseconds 250
[System.Windows.Forms.SendKeys]::SendWait("F")
Start-Sleep -Milliseconds 250
[System.Windows.Forms.SendKeys]::SendWait("A")
Start-Sleep -Milliseconds 250
[System.Windows.Forms.SendKeys]::SendWait("{RIGHT}")
Start-Sleep -Milliseconds 250
[System.Windows.Forms.SendKeys]::SendWait("{DOWN 4}")
Start-Sleep -Milliseconds 100
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
Start-Sleep -Milliseconds 250
[System.Windows.Forms.SendKeys]::SendWait("{TAB 10} \\KFS\Confidential\SMB Neg Pap Letters {ENTER}{TAB 6}")
Start-Sleep -Milliseconds 100
[System.Windows.Forms.SendKeys]::SendWait("$date")
Start-Sleep -Milliseconds 100
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
Start-Sleep -Milliseconds 500
[System.Windows.Forms.SendKeys]::SendWait("%{F4}")
Start-Sleep -Milliseconds 500
[System.Windows.Forms.SendKeys]::SendWait("%{F4}")
Start-Sleep -Milliseconds 500
[System.Windows.Forms.SendKeys]::SendWait("{RIGHT}{ENTER}")

I’ve tried both modules listed above, separating keystrokes in the calls, increasing and decreasing the time between calls.


After attempting to implement Menelaos’ suggestion, I ran into some of the errors I had faced when I tried using that module initially. I’ve been looking into them with no luck, I’ll update if I find a solution to this issue.

Requested object is not available.
At C:\REAL SCRIPTING HOURS\ws2.ps1:15 char:1
+ $document.MailMerge.Destination = [Microsoft.Office.Interop.Word.WdMa ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (:) [], COMException + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
This method or property is not available because the document is not a mail merge main document.
At C:\REAL SCRIPTING HOURS\ws2.ps1:16 char:1
+ $document.MailMerge.Execute()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (:) [], COMException + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException 
:/>  Переменные окружения в Linux - ИТ Проффи