China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-09 13:33
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to obtain the PID of a process and force kill it View 3,460 Replies 21
Original Poster Posted 2007-03-29 12:50 ·  中国 上海 东方有线
新手上路
Credits 14
Posts 4
Joined 2007-03-22 11:33
19-year member
UID 82561
Gender Male
Status Offline
Now the computer is infected with a virus, and the process is abc.exe. Directly using tskill can't kill it at all, but using ntsd -c q -p PID to end the process works. Now I want to implement it with a batch script. I'm a newbie. I read many forum posts and still feel not very good.

@echo off
for /f "tokens=1,2" %%i in ('tasklist') do (
echo %%i | findstr /i "abc.exe" 1>nul 2>nul && (
ntsd -c q -p %%j & set qq=%%i
)
)
if /i not "%qq%"=="abc.exe" echo No virus
echo.
pause

It works under XP, not sure if it works under 2000?
There's one in the forum:
tasklist | findstr "abc.exe"&&goto :p
It's also okay to wrap it, not sure how to do it.
Everyone help simplify it, I also want to learn.
Floor 2 Posted 2007-03-29 13:45 ·  中国 河北 保定 联通
银牌会员
★★★
Credits 1,513
Posts 554
Joined 2005-12-30 00:50
20-year member
UID 48180
Gender Male
Status Offline
Originally posted by lxsky at 2007-3-29 12:50:
How to get the PID of a process and force kill it...



Why do you have to use PID specifically? Can't you just use ntsd -c q -pn abc.exe?
Floor 3 Posted 2007-03-29 23:50 ·  中国 上海 电信
新手上路
Credits 14
Posts 4
Joined 2007-03-22 11:33
19-year member
UID 82561
Gender Male
Status Offline
Hehe, thanks to the 2nd floor, ntsd can indeed be used like this
Floor 4 Posted 2007-03-30 11:52 ·  IANA 局域网IP(Private-Use)
初级用户
★★
Credits 186
Posts 92
Joined 2007-03-27 08:20
19-year member
UID 83047
Gender Male
Status Offline
This is a relatively powerful command,

Taskkill /IM /F abc.exe

If someone says something like only XP machines can use it, then buddy, your machine really needs to be eliminated!
Floor 5 Posted 2007-03-30 12:07 ·  中国 广东 广州 电信
中级用户
★★
脚本爱好者
Credits 238
Posts 93
Joined 2007-03-11 13:38
19-year member
UID 81417
Gender Male
From GZ
Status Offline
Originally posted by lp1129 at 2007-3-29 22:52:
This is a more powerful command,

Taskkill /IM /F abc.exe

If someone says only XP machines can use it, then buddy, your machine really needs to be replaced!



Correct! On XP, you can use taskkill. If you use:

taskkill /f /t /im abc.exe

it's even more powerful, killing its child processes at the same time.
Floor 6 Posted 2007-03-30 12:35 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
If you refuse external termination, taskkill won't work either. Try using kaspersky.
Floor 7 Posted 2007-04-02 00:21 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline

Just to interject, the command format on the 4th floor is incorrect.
Floor 8 Posted 2007-04-02 00:38 ·  中国 广东 广州 联通
银牌会员
★★★
Credits 1,206
Posts 517
Joined 2007-03-25 01:18
19-year member
UID 82819
Gender Male
Status Offline
Originally posted by lp1129 at 2007-3-29 10:52 PM:
This is a more powerful command,

Taskkill /IM /F abc.exe

If someone says only XP machines can use it, then my friend, your machine really needs to be eliminated!


I still, need to consider universality when writing a command.
If it is not supported, then disable your own script on the machine of that object.
Moreover, in China now, many enterprises still use Windows 2000.
知,不觉多。不知,乃求知
Floor 9 Posted 2007-04-02 00:54 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Taskkill.exe copy it over and use it to see
Floor 10 Posted 2007-04-04 01:25 ·  中国 广东 广州 番禺区 电信
中级用户
★★
脚本爱好者
Credits 238
Posts 93
Joined 2007-03-11 13:38
19-year member
UID 81417
Gender Male
From GZ
Status Offline
I remember there is a file inject.dll on the Internet for terminating processes. The usage is (first copy inject.dll to the system32 directory):

rundll32 inject.dll,Install explorer.exe vnetclient.exe qqgame.exe...

After running, it kills the processes vnetclient.exe, QQGame.exe... every 1 second, which can prevent the related processes from starting.

This program will generate this file %windir%\system32\BlackList.config after running. You can edit its content with Notepad to add or delete processes.

Installation:
@echo off
if exist %windir%\system32\inject.dll goto BlackList
copy /y inject.dll %windir%\system32\ >nul
if not exist %windir%\system32\inject.dll exit
rundll32 inject.dll,Install explorer.exe vnetclient.exe
:BlackList
notepad.exe %windir%\system32\BlackList.config|taskkill /f /im cmd.exe

Uninstallation (please save settings before using):
@echo off
reg delete HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v inject /f
taskkill /f /im explorer.exe
ping 0 -n 2 >nul
start explorer.exe
del /f/q %windir%\system32\inject.dll
del /f/q %windir%\system32\BlackList.config

[ Last edited by axi on 2009-1-23 at 22:46 ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
everest79 +8 2007-04-05 13:20
Attachments
inject.rar (51.2 KiB, Downloads: 15)
Floor 11 Posted 2007-04-04 01:39 ·  中国 广西 柳州 电信
初级用户
★★
Credits 168
Posts 78
Joined 2006-12-27 09:58
19-year member
UID 74699
Gender Male
Status Offline
Just kidding, the most amazing thing is shutting down
Floor 12 Posted 2007-04-04 02:16 ·  中国 河北 保定 联通
银牌会员
★★★
Credits 1,513
Posts 554
Joined 2005-12-30 00:50
20-year member
UID 48180
Gender Male
Status Offline
Originally posted by axi at 2007-4-4 01:25:
I remember there is a file inject.dll on the Internet for terminating processes. The usage is (first copy inject.dll to the system32 directory):

rundll32 inject.dll,Install explorer.exe vnetclient.exe qqga ...

This is interesting. Let's give it a try.
Floor 13 Posted 2007-04-04 02:38 ·  中国 湖南 长沙 联通
贫困用户
Credits -2
Posts 20
Joined 2007-01-30 23:49
19-year member
UID 78145
Gender Male
Status Offline
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
NaturalJ0 -3 2007-04-04 03:05
Floor 14 Posted 2007-04-05 13:20 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
Good stuff of 10f, not sure about resource usage
Floor 15 Posted 2007-04-05 21:46 ·  中国 广东 广州 番禺区 电信
中级用户
★★
脚本爱好者
Credits 238
Posts 93
Joined 2007-03-11 13:38
19-year member
UID 81417
Gender Male
From GZ
Status Offline
Thanks to brother everest97 for the points. This thing occupies very little resources. The following is an explanation about it:

ProcessInjector is a DLL injection-based prank software. It can perform the operation of ending the tasks of programs on the user-defined blacklist.

Uses:
* Prevent ignorant guys from using IE to download Adware. (Of course, it means only allowing the use of the firefox browser :) )
* Rescue guys lost in online games
* Make telecommunication employees who come in to install "Sky Speed" return empty-handed

This program takes into account the computer level of the pranked object, and uses the DLL injection technology. There is no physical program; only the DLL is installed into the DLL host process. However, IceSword and Process Explorer can easily detect this program.

Usage method:
Make sure you copy inject.dll to the %SYSTEM32% directory. Enter in Start -> Run:

rundll32 inject.dll,Install <host>

Among them, the host is the process name you want to inject (with the.exe extension). The host can be explorer.exe, or it can be system critical processes such as winlogon.exe, smss.exe, conime.exe, etc. Using system critical processes will make it impossible to end the activity of inject.dll. Once the host is killed, ProcessInjector will stop running. The prohibited program list (with the.exe extension) is the program names that will be added to the blacklist, and they will be killed by inject.dll once per second.

Note: Each time inject.dll is installed, it will overwrite the content of the original blacklist file.

After running this program, a configuration file BlackList.config will be generated, and the "inject" = "rundll32 inject.dll,Install explorer.exe" will be added to the registry startup item. Telecommunication employees will encounter the problem that the main program of Sky Speed "disappears without reason".

Example:
rundll32 inject.dll,Install explorer.exe vnetclient.exe iexplorer.exe qqgame.exe
The program will insert inject.dll into the explorer.exe process, add itself to the system startup item, create the blacklist file %SYSTEM32%\blacklist.config, and kill IE, QQ game, and the main program of Sky Speed all once per second. The program names are case-insensitive.

The generated BlackList.config file:
vnetclient.exe
iexplorer.exe
qqgame.exe

The blacklist file that can be edited in real time:
The blacklist file of ProcessInjector (%SYSTEM32%\BlackList.config) can be edited in real time. ProcessInjector reloads the blacklist once every 10 seconds. You can open the blacklist file with Notepad and add the program names you don't like :)

About resource occupancy:
Under my test environment (Celeron M 1.4G + 512MB memory), ProcessInjector has a negligible impact on the CPU occupancy of the host.

Uninstallation:
Go to HKLM\Software\Microsoft\Windows\CurrentVersion\Run to find the inject item and delete it.
After restarting, delete %SYSTEM32%\blacklist.config and %SYSTEM32%\inject.dll. (Optional)

About this software:
This software is free software. Outmatch guarantees with personality that there is no malicious code, however, it does not guarantee that this program will run correctly on your computer.


[ Last edited by axi on 2007-4-5 at 08:59 AM ]
Recent Ratings for This Post ( 2 in total) Click for details
RaterScoreTime
lxmxn +10 2007-04-05 21:59
baomaboy +4 2007-04-06 05:51
Forum Jump: