Link to home
Start Free TrialLog in
Avatar of c00kie88
c00kie88Flag for Australia

asked on

Taskkill syntax / script

Hi ,

How do i use Taskkill to terminate program except if runs under SYSTEM and local_admin?

I have it as below - it works but if i want both SYSTEM & local_admin? I have tried using AND or & symbol but not working


taskkill /f /fi "imagename eq hello.EXE" /fi "username ne SYSTEM"

Any idea?
Avatar of Adam Leinss
Adam Leinss
Flag of United States of America image

@ECHO on
if '%username%' == 'system' goto end
if '%username%' == 'administrator' goto end

taskkill /f /fi "imagename eq hello.EXE"

:end
exit

Open in new window

Try
tasklist fi "username ne system" /fi "imagename eq some prices.e e"
The same options for tasklist eq taskkill.
Hi,
try this one
 
@echo off

taskkill /f /im hello.exe

pause
Avatar of c00kie88

ASKER

Hi Adam,

I tried below, but still close the program when i login as administrator

@ECHO on
if '%username%' == 'system' goto end
if '%username%' == 'administrator' goto end

taskkill /f /fi "imagename eq hello.EXE"

:end
exit
ASKER CERTIFIED SOLUTION
Avatar of Adam Leinss
Adam Leinss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial