D
D
Dvach2021-12-15 18:03:34
Windows
Dvach, 2021-12-15 18:03:34

How to limit the number of a certain process per Windows user?

There is a certain program.exe that runs on a remote server to which users connect via RDP. Some users are not very smart and may not notice that the program is already running. In this case, the user starts it again. So, dear experts, the question is - how can you limit the number of program.exe processes for a user to one, so that the user can only run one instance?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
rPman, 2021-12-15
@rPman

If there are not many users, you can use taskscheduler, write for each user your own task to launch your application (without a condition), write the corresponding user in each. The task has options - make sure that the application is launched only once, auto-restart, etc.
In this case, specify in the launch shortcut for users not the application itself, but the task launch command schtasks run
Otherwise, write a script in powershell / windows scripting / favorite programming language that will save its pid when the application starts, save it in a file (the file name must contain the name current user, then each user will be allowed to run only 1 instance) and compare it on the next run with the one already running.
You can use the linux way, find / build the flock utility or its analogue, it creates a file with the specified name and blocks it, if successful, runs the specified command otherwise not, the file is unlocked upon completion, in some cases this is suitable
Of course, if the user is scrambled, he will be able to bypass this and launch the application bypassing your shortcut

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question