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-10 06:57
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help]Problem with closing processes using ntsd? View 2,292 Replies 19
Original Poster Posted 2008-10-27 14:40 ·  中国 黑龙江 大庆 联通
高级用户
★★
Credits 547
Posts 261
Joined 2006-04-15 16:50
20-year member
UID 53887
Status Offline
### Question 1:
The problem?
1, Suppose the PID of notepad.exe is 2328, I executed the following command successfully under DOS:
ntsd -c q -p 2328
But when I use it in a batch script like this, it fails:
@echo off
set /p closeprocess= Please enter the PID of the process you want to force close
ntsd -c q -p "%closeprocess%"
goto :eof
The error message is as follows:
Unable to find process '2328', HRESULT 0x80004002
"This interface is not supported"
ntsd: exiting - press enter ---
Why?

2. Also, ask about the specific usage of wmic process delete, is this delete also to force delete the process, including some system processes?

Waiting online......
Floor 2 Posted 2008-10-27 14:59 ·  美国 惠普HP
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
```
@echo off
tasklist|findstr /i "notepad.exe"
echo.
set /p closeprocess=Please enter the PID of the process you want to force close
ntsd -c q -p %closeprocess%
```
Floor 3 Posted 2008-10-27 15:37 ·  中国 黑龙江 大庆 联通
高级用户
★★
Credits 547
Posts 261
Joined 2006-04-15 16:50
20-year member
UID 53887
Status Offline
There is no error prompt after execution, but the process cannot be closed. Adding "%closeprocess%" with "%closeprocess%" has no effect.
Floor 4 Posted 2008-10-27 17:00 ·  中国 黑龙江 大庆 大庆中基石油通信建设有限公司
高级用户
★★
Credits 547
Posts 261
Joined 2006-04-15 16:50
20-year member
UID 53887
Status Offline
Why is that!

ntsd works well under DOS, but fails in batch processing?

Searched for a long time, got some insights on parameter understanding, but it just doesn't work!

ntsd -c q -pn
c :command
q :quit
p :pid
n :processname
Example:
ntsd -c q -pn notepad.exe
or
ntsd -c q -p 2696
Floor 5 Posted 2008-10-27 23:17 ·  中国 广东 深圳 电信
新手上路
坚持学习
Credits 18
Posts 15
Joined 2008-10-18 10:49
17-year member
UID 128642
Gender Male
Status Offline
If ntsd doesn't work, try taskkill, it's very useful.
taskkill /pid xxx
Always use this.
Floor 6 Posted 2008-10-27 23:30 ·  中国 重庆 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
@echo off
tasklist|findstr /i "notepad.exe"
echo.
set /p closeprocess=Please enter the PID of the process you want to forcefully close
ntsd -c q -p %closeprocess%
tasklist|findstr /i "notepad.exe"
echo.

Can you post your result for me to see?
This is mine:
Floor 7 Posted 2008-10-27 23:47 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Use taskkill to end the ntsd process ^

Sometimes when ending the ntsd process, the ntsd window may stay, and you need to close it to end it.
S smile 微笑,L love 爱,O optimism 乐观,R relax 放松,E enthusiasm 热情...Slore
Floor 8 Posted 2008-10-28 00:22 ·  中国 广东 深圳 电信
新手上路
坚持学习
Credits 18
Posts 15
Joined 2008-10-18 10:49
17-year member
UID 128642
Gender Male
Status Offline
It seems that taskkill can't be used in batch processing either. I only used it in the command line before.
Floor 9 Posted 2008-10-28 00:32 ·  中国 重庆 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Who did you hear it from? Or did you personally test it? Can you post your test code and results for us to see?
Floor 10 Posted 2008-10-28 00:54 ·  中国 广东 深圳 电信
新手上路
坚持学习
Credits 18
Posts 15
Joined 2008-10-18 10:49
17-year member
UID 128642
Gender Male
Status Offline
I don't know if it's a problem with the computer or the program.
The following taskkill cannot be used in the for loop batch processing.
for /f "tokens=1,2" %%i in ('tasklist.exe') do if %%i ==notepad.exe taskkill /pid %%j
But if there is only this one: taskkill /im notepad.exe, it can be used, just not in the for loop.
There are others, it seems like taskkill doesn't support variables.
I hope an expert can give guidance.

Today I tested again and found that it's a problem with the program. It should be change %%i==notepad.exe to "%%i"=="notepad.exe", that is, add quotes.
The following is the test program, very simple.
@echo off
start /min notepad.exe
for /f "tokens=1,2" %%i in ('tasklist.exe') do if "%%i"=="notepad.exe" echo %%j
set /p cp=Please enter the PID of the process you want to end
taskkill /pid %cp%

[ Last edited by newsuper on 2008-10-28 at 19:10 ]
Floor 11 Posted 2008-10-28 07:59 ·  中国 黑龙江 大庆 大庆中基石油通信建设有限公司
高级用户
★★
Credits 547
Posts 261
Joined 2006-04-15 16:50
20-year member
UID 53887
Status Offline
I have indeed tested many times, and I also took screenshots, but I don't know how to upload the pictures. Can you tell me how to do it?
I'll try the attachment! There are two pictures
Attachments
2.JPG
Floor 12 Posted 2008-10-28 08:04 ·  中国 黑龙江 大庆 大庆中基石油通信建设有限公司
高级用户
★★
Credits 547
Posts 261
Joined 2006-04-15 16:50
20-year member
UID 53887
Status Offline
The 2nd one, because it kept prompting for the PID of notepad.exe that I needed to enter. There was no way, so I actively closed the CMD window.
Then re-enter CMD and execute
tasklist | findstr /i "notepad.exe"
And see that notepad.exe is still there, not closed. The notepad file I ran before the test is also well in the taskbar, not closed at all, so I said this segment of code of ntsd doesn't work.

The reason I didn't use tasklist to close the process is because I once saw some materials saying:
ntsd can close some processes that tasklist can't close.
Is this statement correct?
Attachments
4.JPG
Floor 13 Posted 2008-10-28 19:21 ·  中国 广东 深圳 电信
新手上路
坚持学习
Credits 18
Posts 15
Joined 2008-10-18 10:49
17-year member
UID 128642
Gender Male
Status Offline
I used ntsd to end the Notepad program.
The method is the same as my 10th floor, just changed the last line of taskkill to ntsd. I don't know what the results are for everyone?
@echo off
start /min notepad.exe
for /f "tokens=1,2" %%i in ('tasklist.exe') do if "%%i"=="notepad.exe" echo %%j
set /p cp=Please enter the PID of the process you want to end
ntsd -c q -p %cp%
Floor 14 Posted 2008-10-28 20:51 ·  中国 重庆 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Did you use the code from floor 6 in this screenshot?
Floor 15 Posted 2008-10-29 10:49 ·  中国 黑龙江 大庆 大庆中基石油通信建设有限公司
高级用户
★★
Credits 547
Posts 261
Joined 2006-04-15 16:50
20-year member
UID 53887
Status Offline
Reply to moderator HAT: Definitely used the code from floor 6, and the result is as my screenshot shows, can't close the process.

Ask newsuper: Can you post the screenshot of your testing process? I simply can't close the notepad.exe process?
Forum Jump: