How To Deal With "." in the middle of a program name In a bat File?

I need to check with a bat file if a program is running in tasksheduler.

The big problem is this program is from external guys and have four "." in the middle of the name.

I'm using this code :

tasklist /fi "IMAGENAME eq Fls.Core.Portal.UI.Shell.exe" 2>NUL | find /I /N "Fls.Core.Portal.UI.Shell.exe">NUL
msg * %ERRORLEVEL%
goto Exit

with program running behind I was expecting the return of errorlevel 0 , but it is returning 1

I believe the problem is this "." in the name of the program.


Solution 1:

You do not have to worry about how to deal with ., this is not the cause of this problem here, this only is about length characters length in tasklist output.

See tasklist for command tasklist | find /i /n "Fls.Core.Portal.UI.Shell.exe" should result in:

[263]Fls.Core.Portal.UI.Shell.exe     8900 Console                    1      4,076 K

But that is never going to happen, the output from tasklist are using precisely 25 characters length for names in, and you are trying find with one string that have 28 characters length tasklist | find /i /n "Fls.Core.Portal.UI.Shell.exe", so, you will never get the desire result using this string with 28 characters length:

Try smaller with 25 characters in string:

tasklist | find /i /n "Fls.Core.Portal.UI.Shell."

You will forever get this output without exe:

[263]Fls.Core.Portal.UI.Shell.     8900 Console                    1      4,076 K

Some suggest code:

@echo off && setlocal enabledelayedexpansion

tasklist | find /I /N "Fls.Core.Portal.UI.Shell." >NUL && (
%__APPDIR__%msg.exe * !errorlevel! zOk, here i'm! & goto Exit:
)|| %__APPDIR__%msg.exe * !errorlevel! nOp, I'm not there! & goto Exit:
   
:Exit:
endlocal

To use the full name in your running query process, try with wmic

wmic process where name="Fls.Core.Portal.UI.Shell.exe" get processid /value 
wmic process where name="Fls.Core.Portal.UI.Shell.exe" get caption /value
wmic process where name="Fls.Core.Portal.UI.Shell.exe" get name /value
  • Use:
wmic process where name="Fls.Core.Portal.UI.Shell.exe" get name | find /v "Name"
  • Output:
Fls.Core.Portal.UI.Shell.exe
  • Get full list descriptions listed:
wmic process where name="Fls.Core.Portal.UI.Shell.exe" get * /format:list
  • Results:

Caption=Fls.Core.Portal.UI.Shell.exe
CommandLine="C:\Users\ecker\AppData\Local\Temp\"Fls.Core.Portal.UI.Shell.exe"
CreationClassName=Win32_Process
CreationDate=20200423222440.079263-180
CSCreationClassName=Win32_ComputerSystem
CSName=LAME_SLUG
Description=Fls.Core.Portal.UI.Shell.exe
ExecutablePath=C:\Users\ecker\AppData\Local\Temp\Fls.Core.Portal.UI.Shell.exe
ExecutionState=
Handle=12752
HandleCount=79
InstallDate=
KernelModeTime=312500
MaximumWorkingSetSize=1380
MinimumWorkingSetSize=200
Name=Fls.Core.Portal.UI.Shell.exe
OSCreationClassName=Win32_OperatingSystem
OSName=Microsoft Windows 10 Pro|C:\Windows|\Device\Harddisk0\Partition4
OtherOperationCount=1505
OtherTransferCount=29348
PageFaults=2228
PageFileUsage=2624
ParentProcessId=11868
PeakPageFileUsage=4236
PeakVirtualSize=2203379519488
PeakWorkingSetSize=4288
Priority=8
PrivatePageCount=2686976
ProcessId=12752
QuotaNonPagedPoolUsage=6
QuotaPagedPoolUsage=46
QuotaPeakNonPagedPoolUsage=6
QuotaPeakPagedPoolUsage=46
ReadOperationCount=14
ReadTransferCount=822
SessionId=1
Status=
TerminationDate=
ThreadCount=1
UserModeTime=0
VirtualSize=2203378040832
WindowsVersion=10.0.18363
WorkingSetSize=4255744
WriteOperationCount=0
WriteTransferCount=0
  • Some further reading:

[√] wmic