Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
Hackoo
- Posts: 103
- Joined: 15 Apr 2014 17:59
#1
Post
by Hackoo » 23 Feb 2016 04:41
Hi
I have this batch for killing some process !
Code: Select all
@echo off
set process=Program with space.exe,winword.exe,Opera.exe,mshta.exe,chrome.exe,calc.exe,skype.exe,iexplore.exe
set Tmp=Tmp.txt
set LogFile=ProcessKillerLog.txt
If Exist %Tmp% Del %Tmp%
If Exist %LogFile% Del %LogFile%
@echo on
For %%a in (%process%) Do Call :KillMyProcess "%%a" %Tmp%
Cmd /U /C Type %Tmp% > %LogFile%
If Exist %Tmp% Del %Tmp%
Exit /b
:KillMyProcess
Taskkill /IM "%1" /F /T >>%2 2>&1
So my aim is to kill a process with space in its name like
"Program with space.exe" what should i modify ?
Thank you !
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#2
Post
by foxidrive » 23 Feb 2016 05:42
Any good?
Code: Select all
set process="Program with space.exe","winword.exe","Opera.exe","mshta.exe","chrome.exe","calc.exe","skype.exe","iexplore.exe"
-
Hackoo
- Posts: 103
- Joined: 15 Apr 2014 17:59
#3
Post
by Hackoo » 23 Feb 2016 06:02
foxidrive wrote:Any good?
Code: Select all
set process="Program with space.exe","winword.exe","Opera.exe","mshta.exe","chrome.exe","calc.exe","skype.exe","iexplore.exe"
Thank you foxidrive
your solution
works
And this another answer here
on stackoverflow
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#4
Post
by foxidrive » 23 Feb 2016 06:10
Ta. The code you showed Jeb is different to here - you need the ~ in the "%%~a" as well as the "%~1"
Code: Select all
For %%a in (%process%) Do Call :KillMyProcess "%%~a" %Tmp%
-
Hackoo
- Posts: 103
- Joined: 15 Apr 2014 17:59
#5
Post
by Hackoo » 23 Feb 2016 06:20
foxidrive wrote:Ta. The code you showed Jeb is different to here - you need the ~ in the "%%~a" as well as the "%~1"
Code: Select all
For %%a in (%process%) Do Call :KillMyProcess "%%~a" %Tmp%
Yes ! I used it like this :
Code: Select all
@echo off
set process="Program with space.exe" winword.exe Opera.exe mshta.exe chrome.exe calc.exe skype.exe
set Tmp=Tmp.txt
set LogFile=ProcessKillerLog.txt
If Exist %Tmp% Del %Tmp%
If Exist %LogFile% Del %LogFile%
For %%a in (%process%) Do Call :KillMyProcess %%a %Tmp%
Cmd /U /C Type %Tmp% > %LogFile%
If Exist %Tmp% Del %Tmp%
Start "" %LogFile%
Exit /b
:KillMyProcess
Taskkill /IM "%~1" /F /T >>%2 2>&1