In wpf you can acess the apps with windows and you are able to close them if you have the id.
Example of code from wpf the method that get the apps
private List<Process> GetProcessesWithWindow()
{
List<Process> processwithwindow = new List<Process>();
Process[] processes = Process.GetProcesses();
foreach (Process p in processes)
{
if (!String.IsNullOrEmpty(p.MainWindowTitle))
{
processwithwindow.Add(p);
}
}
return processwithwindow;
}
}
}
Now the one that block them
Task Blocker = new Task(() =>
{
while (M != minutes)
{
processwithwindow = GetProcessesWithWindow();
foreach (Process p in processwithwindow)
{
if (Usefulprograms.Any(program => program.Id == p.Id ) == false)
{
p.Kill();
}
}
};
}
);
There it's a way to achieve this in uwp? I seek and the only thing that I found it's this api https://blogs.windows.com/windowsdeveloper/2017/06/28/uwp-app-diagnostics/ But that only allow me to access to uwp apps and I can't get properties as mainwindotitle or method like kill.
CodePudding user response:
There it's a way to achieve this in uwp?
Not directly as the app runs in a security constrained sandbox with limited privileges. This is by design for UWP apps.
You could however add a full-trust desktop extension component your UWP app that runs the GetProcessesWithWindow()
method. Please refer to Stefan Wick's blog for more information and examples.
CodePudding user response:
There it's a way to achieve this in uwp?
No, there is no way to do that in UWP apps. UWP apps are running in the sandbox that is isolated from the system. So UWP apps can't directly do actions to the system processes. The UWP App Diagnostics API also shows that you could only get information about the processes.