I am trying to close an exe process located in a specific directory, using the %appdata%
variable, but it doesn't work.
WMIC Process Where "ExecutablePath='%APPDATA%\\Adobe\\screenrecorder.exe'" Call Terminate
If I try to close the process without %appdata%
it works as intended.
WMIC Process Where "ExecutablePath='C:\\Users\\Admin\\AppData\\Roaming\\Adobe\\screenrecorder.exe'" Call Terminate
It is essential that it must work using %appdata%
, does someone know how to close an exe file using %appdata%?
You should have noted that backward slashes in a path require escaping in the WHERE clause of WMIC, so you simply need to expand the environment variable, and substitute the backward slashes for escaped backward slashes. The general method of doing that is %VariableName:CharToSubstitute=SustitutionChars%
WMIC Process Where "ExecutablePath='%AppData:\=\\%\\Adobe\\screenrecorder.exe'" Call Terminate
Or more robustly
%SystemRoot%\System32\wbem\WMIC.exe Process Where "ExecutablePath='%AppData:\=\\%\\Adobe\\screenrecorder.exe'" Call Terminate