1

I'm running a program in multiple instances of a single .exe file on Windows 10

for examaple if I open up 3 instances of "example.exe" it will show up process name in task manager like.

example.exe
example.exe
example.exe

I want assign number after each process like.

example - 01.exe
example - 02.exe
example - 03.exe
................
................
................
example - 99.exe

So that I can setup rules from another program to interact with each running process.

Is there any solution for this problem?

Thank you.

Lucius
  • 11
  • 2
  • Please don't spam the tags. Which programming language of the three tagged above are you using? Also, is this executable program written by you, or is it a third-party one? – 41686d6564 stands w. Palestine Jun 16 '20 at 03:26
  • It's a third-party one. Sorry, i'm new to stackoverflow. – Lucius Jun 16 '20 at 03:28
  • No worries, and welcome to Stack Overflow! I don't think what you're trying to do is possible without copying/renaming the executable but it most likely isn't the best approach anyway. You should probably rely on the Process ID instead. Please edit the question and show us how you currently start the processes. – 41686d6564 stands w. Palestine Jun 16 '20 at 03:32
  • In the Windows API, it's possible to add a process to a named kernel Job object. Membership can be checked via `IsProcessInJob`, and the processes in the Job can be listed via `QueryInformationJobObject`: `JobObjectBasicProcessIdList`. This is a roundabout way to 'name' a process. – Eryk Sun Jun 16 '20 at 22:24

1 Answers1

0

As Ahmed points out in the comments, Windows sort of autonumbers a process for you by creating a process ID and this could be used to differentiate between them. The problem is that process id isn't sequential like you have here. You could sort them by process id and assign your own numbering but if one process quits the numbering changes for all those processes after it, which could be a problem for you. You could always start the processes, retrieve their IDs and maintain the mapping of 01 is process ID x, 02 is process ID y etc yourself and pass it round your program

You could also consider to start each app with command line arguments, that you can later retrieve with one of the techniques mentioned here so when you three times launch your exes you could:

for(int x = 1; x <= 3; x++)
  Process.Start("example.exe", x.ToString());

Example should be capable of ignoring the dummy argument, though. If it will heed it, find some way to make it a no-op

If all this fails, maybe just having 99 copies of the same exe, names accordingly, in a folder and ready to go would be the simplest trick

Caius Jard
  • 72,509
  • 5
  • 49
  • 80