首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >针对特定用户的taskkill

针对特定用户的taskkill
EN

Stack Overflow用户
提问于 2013-07-21 04:13:13
回答 1查看 4K关注 0票数 1

如何使用这两个代码杀死同一用户的多个任务?

代码no1

代码语言:javascript
复制
@ECHO OFF

TASKKILL /F /IM explorer.exe
cls
Echo "Please Specify the User ID"

Set /p u=
set USER=%u%@%userdomain%


Echo "Please Specify the PASSWORD"
runas /user:%USER% Explorer.exe
cls

echo "Press any key to Switch Back to Default USer Profile"
Pause
Echo "please enter your password again for verification"
runas /user:%USER% C:\switch.bat
pause
cls
start %windir%\explorer.exe
exit

代码no2 (此文件名为Switch.bat)

代码语言:javascript
复制
@echo off

TASKKILL /F /IM Explorer.exe

exit

实际上,创建它的总体思路是在不注销的情况下切换到win XP,如win 7

问题是,当它切换回原始配置文件时,第二个用户的所有任务都不会停止

是否有办法停止正在运行特定用户的所有任务

EN

回答 1

Stack Overflow用户

发布于 2013-07-21 04:35:38

您可以尝试使用tskill。它可以终止一个进程,并接受用户ID作为参数:

删除同一用户的资源管理器

代码语言:javascript
复制
  setlocal enabledelayedexpansion
    set exe_name=Explorer
    for /f "skip=1 tokens=1,2,3" %%S in ('query user') do (
            set "current_user=%%S"

            if "!current_user:~0,1!" EQU ">" (
                    for /f "tokens=2 delims= " %%M  in ('tasklist ^| find ^"%exe_name%^"') do (
                            tskill "%%M"    /ID:%%U
                    )

            )
    )
    endlocal
    goto :eof

对于所有其他用户:

代码语言:javascript
复制
       setlocal enabledelayedexpansion
set exe_name=Explorer
        for /f "skip=1 tokens=1,2,3" %%S in ('query user') do (
                set "current_user=%%S"

                if "!current_user:~0,1!" NEQ ">" (
                        for /f "tokens=2 delims= " %%M  in ('tasklist ^| find ^"%exe_name%^"') do (
                                tskill "%%M"    /ID:%%U
                        )

                )
        )
        endlocal
        goto :eof
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17766291

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档