简体   繁体   中英

Mute Windows 10 Notification using C# or WPF

I'm currently researching on how to mute the windows 10 notification but it i havent found any concrete solution yet.

What i want to do is to disable all notifications when i press a button or check a checkbox. It is similar on what you do on the notification settings, but i want it to do it progmatically on my application.

I'm currently reading the document of microsoft about Notification Listener. https://docs.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/notification-listener

NotificationListener allows you to access the notifications, but not to the configuration of the system. And you must think it's a UWP Api... You want to do something that can not be done in UWP Api(impossible) nor WPF(possible, i wish you good luck).

You can't change system settings inside the UWP app box -safety and things-. The way to do it is "Open the Configuration App where you want the user make the change".

If you wan't to this in WPF/.net you'd have to play with PInvoke and WinApi seriously. And that means thinking about privileges , run as admin, find the functions in WinApi .h files , etc...

Keeping simple, in UWP, nope; in WPF, you have to read a lot of source code/documentation of Windows .h files, make the c# version of the structs, etc...

The real question here is... It's necessary? Windows provides Focus Assist with two clicks (corner, Focus Assist)

I really appreciate your feedbacks! I did some tinkering and found out the service responsible for the notification. I'm not really confident that this is the best approach, but it is working for me.

What I did was I stopped the service using C#. Here is my sample code:

  ServiceController[] services = ServiceController.GetServices();

        foreach (ServiceController service in services)
        {
            if (service.ServiceName.Contains(serviceName))
            {
                service.Start();

            }


        }

Here is the service responsible for the notifications: Notification Service

I dont know if this is a good practice or not so I'm still open for feedbacks and suggestions.

Thank you!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM