Windows service + Process[]

Hi i have a problem usign the function Process[] currentProcesses = Process.GetProcesses();

( Creates a new System.Diagnostics.Process component for each process resource on the local computer.)

it works fine when i test it from a windows form, but a i need to create a windows services and when run the services the values MainWindowTitle gives empty and MainWindowHandle gives 0, can anybody help me or give another way to do it.

Here is my code:

// Here gets the process
 Process[] currentProcesses = Process.GetProcesses();

// Here te function where i checke those values
 private List<IntPtr> SearchProcess(BLL.clsApplicationAppBlocker app, Process[] pro)
{
   return pro.Where(p => p.MainWindowTitle
                          .ToLower()
                          .Contains(app.WindowsTitle.ToLower())
                      && p.MainWindowHandle != IntPtr.Zero)
             .Select(p => p.MainWindowHandle)
             .ToList();
}

Upvotes: 0

Views: 69

Answers (1)

Sasaman
Sasaman

Reputation: 272

Windows Service runs in isolated session, there is some workarounds. I think that you have problem mentioned here, please read this thoroughly:

Windows Service Isolated Session

Upvotes: 1

Related Questions