D
D
Dvach2021-12-22 12:36:34
cmd/bat
Dvach, 2021-12-22 12:36:34

Run the program only if there is no running instance of the user's bat script?

You need to run the program only if the user has not opened it yet, shortcut scheme → script (bat) → launch if there is no process

Actually, there is a great thing that does what you need

tasklist /FI "USERNAME eq %username%" /FI "IMAGENAME eq program.exe " 2>NUL | find /I /N "program.exe">NUL
if "%ERRORLEVEL%" == "1" "C:\program.exe"

Problem - the script must be executed by an ordinary user, not an admin, but when adding /FI "USERNAME eq %username%" the script hangs, it can only be cured by running from the admin, but this option is not suitable for two reasons
1) The user does not have admin rights (Kep)
%username% is meaningless

What is it connected with? Without a username, the script executes but, logically, searches for all users. How can I get around the problem so that the script works without admin rights and for the specific user that runs it

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Olgeir, 2021-12-22
@Dvach

The chain of find'ov will not solve a problem?
| find /I /N "program.exe">NUL | find /I /N "%username%">NUL

A
Alexander, 2021-12-22
@SmoKE_xD

Use PowerShell

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question