Windows Batch File - CLS command not working - windows

Running on Windows 10 Pro 64-bit [Version 10.0.17763.1637];
I'm writing a simple batch file to show active processes:
cls
echo.
echo Showing all processes similar to %1*
tasklist /FO table /FI "IMAGENAME eq %1*"|more
However, I see that the screen is not being cleared as the script is launched (CLS works fine if I invoke it manually from my Command Line).
I know it's actually a quite silly issue, I'm just curious to know why that hppens and if there's any workaround.
Thanks in advance!
Massimo

i checked your script and cls works perfect(except for it isn't showing active processes) you just need to add #echo offand also validate encoding as ANSI if it isn't,if you want command line without prompt,here it is:
#echo off
cls
echo.
echo Showing all processes similar to %1*
tasklist
rem tasklist /FO table /FI "IMAGENAME eq %1*"|more

Related

How to tell if a process is running via batch or script file? [duplicate]

This question already has answers here:
How to check if a process is running via a batch script
(19 answers)
Closed 6 years ago.
How can I tell if a specific process is running using a batch file?
For example, How can I tell if notepad.exe is running?
Consider the following proposal (run in your batch file):
tasklist | findstr /R ^notepad.exe
Simple, but works!
tasklist /?
Will show you a lot of great options for filtering and managing your output.
findstr /?
Will also show you a great set of options to search and filter the output of tasklist
I hope this helps.
Powershell has an in-built function. Get-Process
Get-Process will tell you about all the processes. If you wish to filter with a particular one then use :
Get-Process|?{$_.Name -eq 'Notepad'}
Screenshots are for reference:
Type Powershell in cmd prompt:
Run the above query. If the notepad is running. It will show you:
Hope it helps...
You can do something like this in batch file :
This one is inspired from Check if a process is running or not?
#echo off
Title Check for running process . . .
mode con cols=50 lines=3
set "MyProcess=notepad.exe"
set delay=5
:Main
cls
Tasklist /FI "IMAGENAME eq %MyProcess%" | find /I "%MyProcess%">nul && (
echo( & Color 9A
echo PROCESS "%MyProcess%" IS RUNNING !
)||(
echo( & Color 4C
echo PROCESS "%MyProcess%" IS NOT RUNNING !
)
Timeout /T %delay% /nobreak>nul
Goto Main

Need help using tasklist to check if the Battle.net process

I am trying to create a batch file as an impromptu shortcut to launch the Battle.net client and when it fully opens, to launch Hearthstone specifically but i'm sure it can be applied to any Blizzard game.
The problem is when I run
start "" "C:\Program Files (x86)\Hearthstone\Hearthstone Beta Launcher.exe"
tasklist /fi "IMAGENAME eq battle.net.exe" 2>NUL | find /I /N "battle.net.exe">NUL
if "%ERRORLEVEL%"=="0" echo Battle net is ready
And if that worked then I would use start "" "battlenet://WTCG" but it immediately echos even though nothing is visible on my screen and the process is not running in task manager. Which means it would try to launch hearthstone without Battle.net being open even though the script says it is.
Is this just an issue with Battle.net processes or am I doing something very wrong? I am currently using Windows 10 if it matters.

Cannot kill a process using the window title

I have two batch file one is always running (listerner.bat) but it is visible,the other one (mystop.bat)is to kill or stop my listener.bat and this two batch file are resides in this path C:\mydemo\mybatchfiles\,I am using windows 7
here is the code for mystop.bat
taskkill /F /FI "WINDOWTITLE eq Administrator: testlistener" /T
but when I run it,it will not terminate the running (listener.bat),There is no error but I have this message when I run it.
INFO: No tasks running with the specified criteria.
I appreciate someone can help me on this.I am new on this batch file command.
I had the same problem. In my case it was that there were two spaces in the window title:
taskkill.exe /F /FI "WindowTitle eq Administrator: TailingErrorLog"
^^
Taskkill considers the command currently executed by listener.bat as part of the title. So you need to add a wildcard "*".
taskkill /F /FI "WINDOWTITLE eq Administrator: testlistener *" /T
Try terminating using Im switch ..
Taskkill /Im listener.bat /t /f
Although this is not computer science related question , thought I should help ...

Batch file to uninstall a program

I'm trying to uninstall a program EXE via batch file and am not having any success.
The uninstall string found in the registry is as follows:
C:\PROGRA~1\Kofax\Capture\ACUnInst.exe /Workstation
C:\PROGRA~1\Kofax\Capture\UNWISE.EXE /U
C:\PROGRA~1\Kofax\Capture\INSTALL.LOG
If I run that from CMD or batch it does nothing.
If I run C:\PROGRA~1\Kofax\Capture\UNWISE.EXE /U from CMD it will open up a dialog box to point to the INSTALL.LOG file and then proceed to uninstall.
At the end, it will ask me to click finish.
I need this to be silent, can you point me in the right direction? This is on XP and 7.
Every program that properly installs itself according to Microsoft's guidelines makes a registry entry in either HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall (for machine installs) or HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall (for user profile installs). Usually, the key for the program will be its GUID, or else the name of the program. Within that key will be an entry called UninstallString. This contains the command to execute to uninstall the program.
If you already know ahead of time what you will be uninstalling, it should be easy enough to just put that in your batch file. It gets tricky when you try to automate that process though. You can use the reg command to get data from the registry, but it returns a lot of text around the actual value of a given key, making it hard to use. You may want to experiment with using VBscript or PowerShell, as they have better options for getting data from the registry into a variable.
This might help you further.....
How to Create a script via batch file that will uninstall a program if it was installed on windows 7 64-bit or 32-bit
I've had the same problem and this is what I came up with.
Before you start using this method though, you might wanna look up the name of the application on WMIC using CMD so..
First you wanna do: WMIC product > C:\Users\"currentuser"\Desktop\allapps.txt
I'd recommend to output the command to an TXT file because it's really confusing to read it in the Cmd prompt, plus is easier to find the data you are looking for.
Now what you wanna do is find the actual name of the app... If you look at the code I put in, the app name says SkypeT because skype has "™" in the end of it and the command prompt can't interpretate that as it is.
After you got the app name, just put in the find in the 4th line and substitute, a few lines which contain my examples with skype...
Also you can probably creat a variable called %APP% and not worry as much, but at it's current it works just fine...
One thing to note! with me the msi /quiet command did not work, the program would not install or uninstall so I used /passive, which lets the users see what's going on.
#Echo off
CD %cd%
:VerInstall
for /f "tokens=12,*" %%a in ('wmic product list system ^| Find /I "SkypeT"') do (
if Errorlevel = 0 (
Echo Skype is installed! )
if Errorlevel = 1 ( Echo Skype is not installed, proceding to the installation!
Ping localhost -n 7 >nul
goto :Reinstall )
)
:Status
tasklist /nh /fi "IMAGENAME eq "APP.exe" | find ":"> nul
if errorlevel = 1 goto :force
goto :Uninstall
:Force
echo We are killing the proccess... Please do not use the application during this process!
Ping localhost -n 7 > nul
taskkill /F /FI "STATUS eq RUNNING" /IM APP* /T
echo The task was killed with success! Uninstalling...
Ping localhost -n 7 > nul
:Uninstall
cls
for /f "tokens=12,*" %%a in ('wmic product list system ^| Find /I "SkypeT"') do (
set %%a=%%a: =%
msiexec.exe /x %%a /passive /norestart
)
:DoWhile
cls
Tasklist /fi "IMAGENAME eq msi*" /fi "STATUS eq RUNNING" | Find ":" >nul
if errorlevel = 1 (
echo Installation in progress
Goto :DoWhile
)
echo Skype is Uninstalled
:Reinstall
msiexec.exe /i SkypeSetup.msi /passive /norestart
:reinstallLoop
Tasklist /fi "IMAGENAME eq msi*" /fi "STATUS eq RUNNING" | Find ":" >nul
if errorlevel = 1 (
echo Installation in progress
goto :reinstallLoop
)
echo Skype is installed
:end
cls
color 0A
Echo Done!
exit
One last thing. I used this as an Invisible EXE task, so the user couldn't interact with the command prompt and eventually close the window (I know, I know, it makes the whole echoes stupid, but it was for testing purposes).for that I used BAT to EXE converter 2.3.1, you can put everything to work on the background and it will work very nicelly. if you want to show progress to users just write START Echo "info" and replace the info with whatever you want, it will open another prompt and show the info you need.
Remember, Wmic commands sometimes take up to 20 seconds to execute since it's querying the conputer's system, so it might look like it's doing nothing at first but it will run! ;)
Good luck :)
We needed a batch file to remove a program and we couldn't use programmatic access to the registry.
For us, we needed to remove a custom MSI with a unique name. This only works for installers that use msi or integrate such that their cached installer is placed in the Package_Cache folder. It also requires a unique, known name for the msi or exe. That said, it is useful for those cases.
dir/s/b/x "c:\programdata\packag~1\your-installer.msi" > removeIt.bat
set /p RemoveIt=< removeIt.bat
echo ^"%RemoveIt%^" /quiet /uninstall > removeIt.bat
removeIt.bat
This works by writing all paths for 'your-installer.msi' to the new file 'removeIt.bat'
It then assigns the first line of that bat file to the variable 'RemoveIt'
Next, it creates a new 'removeIt.bat' that contains the path/name of the .msi to remove along with the needed switches to do so.
Finally, it runs the batch file which executes the command to uninstall the msi. This could be done with an .exe as well.
You will probably want to place the 'removeIt.bat' file into a known writable location, for us that was the temp folder.

Batch list open windows

I am trying to write a windows batch file that will print and execute a command if a window is open on the system. I can do this with a process but this is not the effect i want. I want to know if a window is open if so then print open if not do nothing, If there is a way that i can do this please let me know. Better description is when you open taskmanager and the first tab shows open windows. I just want a list of these windows and then from there just search for a program such as googlechrome.exe
Thank you all in advanced!
To see which executables are running from the command line, use: tasklist.exe. This enables you to filter on a WINDOWTITLE attribute as well. Beyond that, you might be out of luck.
Example to see if an untitled notepad instance is running:
tasklist /FI "WINDOWTITLE eq Untitled - Notepad"
You might use this inside a batch file as follows:
FOR /F "tokens=* USEBACKQ" %%F IN (`tasklist /FI "WINDOWTITLE eq Untitled - Notepad" ^| find/c "exe"`) DO (
SET windowcount=%%F
)
echo %windowcount%
if "%windowcount%"=="0" (
echo no windows!
) ELSE (
echo %windowcount% windows found!
)

Resources