【发布时间】:2020-12-10 08:50:14
【问题描述】:
【问题讨论】:
标签: windows powershell
【问题讨论】:
标签: windows powershell
没有直接的方法可以使用 PowerShell 进行检查, 但也许您可以检查注册表值并返回该值并使用 if-else 条件来满足您的代码。
通常ToastEnabled DWORD 的值位于
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\PushNotifications 表示PushNotifications 的状态
如果 ToastEnabled DWORD,
0 = PushNotifications Turn off
1 = PushNotifications Turn on
以下代码将帮助您阅读,无论该值是 1 还是 0。
$key = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\PushNotifications'
(Get-ItemProperty -Path $key -Name ToastEnabled).ToastEnabled
此外,如果您愿意,可以检查"Action Center in Windows" 是否已被禁用
$key2 = 'HKCU:\Software\Policies\Microsoft\Windows\Explorer'
(Get-ItemProperty -Path $key -Name DisableNotificationCenter).DisableNotificationCenter
注意DisableNotificationCenter 不是像ToastEnabled 一样的默认键。必须有人手动创建它。因此,如果尚未创建,您将看不到 0。相反,您可能会得到
Get-ItemProperty : Property DisableNotificationCenter does not exist at path
【讨论】: