Vladimir Amiorkov
Vladimir Amiorkov

Reputation: 2921

How to detect if a program (Process) is running and get its instance in a Windows 8.1 Universal App

I am new to the world of Windows Universal Apps but I find it very interesting field so I wanted to start getting to know its capabilities.

I am currently an WPF .NET developer and I want to be able to check if a program is currently running and get its instance. In WPF I would do this with the help of Process.GetProcessesByName() but Process is not available in an Universal app. Is there a similar way of getting a process (running program's instance) in Windows 8.1 Universal App?

Upvotes: 4

Views: 1901

Answers (2)

Franklin M Gauer III
Franklin M Gauer III

Reputation: 61

System.Diagnostics.Process is not available in a UWP app. Those apps are sandboxed and are not allowed to look at the other processes running on the machine.

Upvotes: 5

DeshDeep Singh
DeshDeep Singh

Reputation: 1853

Add this line to your using list:

using System.Diagnostics;

Now you can get a list of the processes with the Process.GetProcesses() method, as seen in this example:

Process[] processlist = Process.GetProcesses();

foreach(Process theprocess in processlist){
Console.WriteLine(“Process: {0} ID: {1}”, theprocess.ProcessName, theprocess.Id);
}

Some interesting properties of the Process object that also may be required:

p.StartTime (Shows the time the process started)
p.TotalProcessorTime (Shows the amount of CPU time the process has taken)
p.Threads ( gives access to the collection of threads in the process)

Upvotes: 1

Related Questions