Gosoddin
Gosoddin

Reputation: 11

System.Management currently is only supported for Windows desktop applications

Here im using UWP Application for tracking Application closed or Open

Im Getting This error While Loading startProcWatcher = new ManagementEventWatcher(scope, queryString); Code:

string queryString =
                "SELECT TargetInstance" +
                "  FROM __InstanceCreationEvent " +
                "WITHIN  .025 " +
                " WHERE TargetInstance ISA 'Win32_Process' "
                //+ "   AND TargetInstance.Name = '" + processName + "'";
                + "   AND TargetInstance.Name like '%'";

            // The dot in the scope means use the current machine
            string scope = @"\\.\root\CIMV2";

            // Create a watcher and listen for events
            startProcWatcher = new ManagementEventWatcher(scope, queryString);
            startProcWatcher.EventArrived += ProcessStarted;
            startProcWatcher.Start();

Please Give any suggestion for Overcome This Issue

Upvotes: 0

Views: 4338

Answers (1)

Roy Li - MSFT
Roy Li - MSFT

Reputation: 8666

Please take a look at the document for ManagementEventWatcher Class. It mentioned that it is only available for some .NET framework version and .NET Platform Extensions. It is not supported for UWP apps.

If you want to do something when the app is opened or before the app is closing, you could do it during the onlaunched event and the Application.Suspending Event. For more information, you could check UWP app lifecycle.

Upvotes: 1

Related Questions