batch IF Statements in Batch Files
15 hours ago, LinusTechTipsMember said:can i add 2 programs? like
Easiest way is just nesting it
echo off tasklist /fi "imagename eq firefox.exe" | find /i ".exe" >null if not errorlevel 1 ( echo "Firefox found checking for chrome" tasklist /fi "imagename eq chrome.exe" | find /i ".exe" >null if not errorlevel 1 ( echo "both tasks found" echo "Do your work here for both found" ) else ( echo "firefox found not chrome though" echo "Do your work here if firefox detected but not chrome" ) ) else ( echo "task not found" echo "Do your work here if firefox not detected" )
15 hours ago, LinusTechTipsMember said:forgive me about the ethernet part,
i mean make an option for "Ethernet" only,
i want to make a command like
Easy enough to exploit the find command again...the find command processes line by line...so this time we exploit it by creating lines only with "Ethernet" in it, and the searching for "enabled"
echo off netsh interface show interface | find /i "Ethernet" | find /i "Enabled" >null if not errorlevel 1 ( echo "disconnect code here" ) else ( echo "Ethernet is currently disabled or doesn't exist" )
15 hours ago, RZomerman said:that is pretty old shit.. perhaps go more towards PowerShell - it allows way more variables and options.. and seems to be more of the default with later Windows versions.. (oh and it also runs on linux)..
Or go Bash shellscript... but leave CMD in its grave..
It's old, but so many people overlook it just because of that. I'd like to see something like this done in powershell with less effort (and the ability to just double click to run). Lots of computers have powershell disabled or you need to do set-executionpolicy remotesigned when running it...which to me doesn't seem nearly as elegant and seems more cumbersome
Powershell is more powerful, but honestly given that it's not just double click and run is its downfall...along with the fact that it has a lot higher learning curve the cmd.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now