-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,442
  • 2
  • 25
  • 31
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.
  • 98
  • 14
misticos
  • 668
  • 4
  • 20
  • 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