Category filter
Script to play a beep sound on Windows devices
The Windows beep command produces a beeping sound through the computer’s speaker. This command can be employed to test the speaker’s functionality or generate various signals for the user. Predominantly, generating such reverberations can signal the user about an operation that has been completed or that the device needs attention. With Hexnode UEM admins can remotely play a beep sound for a specified period on Windows devices by using customized scripts.
PowerShell script
Executing this script will play the beep sound on the device.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
try{ #determining the current logged in user $currentLoggedInuser="" $signedInUsers=get-wmiobject win32_process | where-object {$_.processname -eq "explorer.exe"} | Foreach ({$_.getowner().user}) foreach($user in $signedInUsers) { $isactive = C:\windows\system32\qwinsta.exe $user if($isactive -like "* Active*") { $currentLoggedInuser = $user break } } if($currentLoggedInuser -eq "") { Write-Host "cannot find any logged in user, so skipping script execution`nTo execute this script, atleast one user must be logged-in to the device" } else { Write-Host "Device beep generated for user: ",$currentLoggedInuser $script = "Start-Process ""$file"" -PassThru -Wait" #unregistering ShowNotificationTask task from task scheduler (if we have already registered using script execution) try { $a=Unregister-ScheduledTask -TaskName "ShowNotificationTask" -Confirm:$false -ErrorAction:Ignore } catch { Write-Host "error while unregistering sheduletask-->",$_.Exception.Message } #scheduling task $actions = (New-ScheduledTaskAction -Execute 'powershell.exe' -WorkingDirectory C:\Hexnode\Logs -Argument "-ExecutionPolicy unrestricted -WindowStyle Hidden -NoLogo -command `"&{[console]::Beep(1000,5000)}`"") $principal = New-ScheduledTaskPrincipal -UserId $currentLoggedInuser -RunLevel Highest $settings = New-ScheduledTaskSettingsSet -WakeToRun -DontStopIfGoingOnBatteries -DontStopOnIdleEnd -Hidden -AllowStartIfOnBatteries -Priority 0 -StartWhenAvailable $task = New-ScheduledTask -Action $actions -Principal $principal -Settings $settings $reg= Register-ScheduledTask 'ShowNotificationTask' -InputObject $task Start-ScheduledTask -TaskName "ShowNotificationTask" -Verbose } } catch { Write-Host "Exception inside running script-->",$_.Exception.Message } |
In the above script, there are two values mentioned next to the beep command. The first value specifies the frequency of the beep sound which ranges from 37 to 32767 and the second value is to specify the time period in milliseconds for how long the beep sound should prevail.