【问题标题】:Powershell: Is there a programmatic way to determine is Notification is enabled on Windows 10?Powershell:是否有一种编程方式来确定 Windows 10 上是否启用了通知?
【发布时间】:2020-12-10 08:50:14
【问题描述】:

我编写了一个脚本来在 Windows 10 中发送通知,但它默默地失败了。然后我意识到通知已关闭。但我似乎找不到是否有命令检查通知是打开还是关闭。

如何以编程方式检查通知是打开还是关闭?

【问题讨论】:

    标签: windows powershell


    【解决方案1】:

    没有直接的方法可以使用 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 
    

    【讨论】:

      猜你喜欢
      • 2013-08-12
      • 2011-03-07
      • 1970-01-01
      • 2011-09-23
      • 2012-01-28
      • 2010-12-04
      • 1970-01-01
      • 1970-01-01
      • 2011-02-19
      相关资源
      最近更新 更多