-4

I try this:

int yourProcess = Process.GetProcessesByName( "notepad.exe" )[0].Id;

all i get is this error:

System.IndexOutOfRangeException: 'Index was outside the bounds of the array.'

can anyone help?

shahaf
  • 4,750
  • 2
  • 29
  • 32
ANdrei
  • 1

1 Answers1

-1

You tried to get processes by their name, but you didn't find any. That's your only error, you should specify a friendly name of the process. Or rather iterate through all processes and find the one you need.

Marek S.
  • 108
  • 14
misticos
  • 718
  • 5
  • 22
  • Note this won't work on any internationalized Windows version, since friendly names will vary dependent of the language used. – Lukasz032 Oct 04 '19 at 16:38