找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 68401|回复: 16

[系统相关] 批处理开启和结束进程(已解决)

[复制链接]
发表于 2014-11-24 11:22:42 | 显示全部楼层 |阅读模式
本帖最后由 wushui 于 2014-11-25 11:14 编辑

打开一个程序  例如 1.exe        两种方式为   1.exe    带参数   1.exe -aaa
打开后有两个进程都叫1.exe   我怎么写两个批处理,分别关闭这两个(进程名相同)?

打开的两个命令:
start 1.exe
start 1.exe -aaa
关闭带参数的:   wmic process where commandline="1.exe -aaa" call terminate
关闭不带参数的:wmic process where "CommandLine<>'1.exe -aaa' and name='1.exe'" call terminate
发表于 2014-11-24 13:00:49 | 显示全部楼层
  1. taskkill /f /im a.exe
复制代码
 楼主| 发表于 2014-11-24 13:08:06 | 显示全部楼层
回复 2# DAIC


有两个a.exe进程,  第一个是直接打开,第二个是参数打开。
我要只关闭第二个,你这样两个都关了
发表于 2014-11-24 13:51:34 | 显示全部楼层
回复 3# wushui


执行命令:
  1. wmic process where name="a.exe" get * /value > 1.txt
复制代码
把 1.txt 的内容发出来看看
 楼主| 发表于 2014-11-24 14:12:31 | 显示全部楼层
回复 4# DAIC


   

Caption=a.exe
CommandLine=a.exe
CreationClassName=Win32_Process
CreationDate=20141124135500.841075+480
CSCreationClassName=Win32_ComputerSystem
CSName=WIN-F0287INACU7
Description=a.exe
ExecutablePath=E:\Debug\a.exe
ExecutionState=
Handle=3148
HandleCount=448
InstallDate=
KernelModeTime=10296066
MaximumWorkingSetSize=1380
MinimumWorkingSetSize=200
Name=a.exe
OSCreationClassName=Win32_OperatingSystem
OSName=Microsoft Windows 7 Ultimate |C:\Windows|\Device\Harddisk1\Partition2
OtherOperationCount=10895
OtherTransferCount=84038
PageFaults=43001
PageFileUsage=105596
ParentProcessId=5128
PeakPageFileUsage=105600
PeakVirtualSize=463982592
PeakWorkingSetSize=121800
Priority=8
PrivatePageCount=108130304
ProcessId=3148
QuotaNonPagedPoolUsage=50
QuotaPagedPoolUsage=640
QuotaPeakNonPagedPoolUsage=52
QuotaPeakPagedPoolUsage=698
ReadOperationCount=6173
ReadTransferCount=12324004
SessionId=1
Status=
TerminationDate=
ThreadCount=16
UserModeTime=423542715
VirtualSize=427761664
WindowsVersion=6.1.7601
WorkingSetSize=124252160
WriteOperationCount=11
WriteTransferCount=3653


Caption=a.exe
CommandLine=a.exe  -aaa
CreationClassName=Win32_Process
CreationDate=20141124135505.628349+480
CSCreationClassName=Win32_ComputerSystem
CSName=WIN-F0287INACU7
Description=a.exe
ExecutablePath=E:\Debug\a.exe
ExecutionState=
Handle=7272
HandleCount=447
InstallDate=
KernelModeTime=8736056
MaximumWorkingSetSize=1380
MinimumWorkingSetSize=200
Name=a.exe
OSCreationClassName=Win32_OperatingSystem
OSName=Microsoft Windows 7 Ultimate |C:\Windows|\Device\Harddisk1\Partition2
OtherOperationCount=7514
OtherTransferCount=84597
PageFaults=42980
PageFileUsage=102204
ParentProcessId=8676
PeakPageFileUsage=107300
PeakVirtualSize=455192576
PeakWorkingSetSize=123164
Priority=8
PrivatePageCount=104656896
ProcessId=7272
QuotaNonPagedPoolUsage=50
QuotaPagedPoolUsage=635
QuotaPeakNonPagedPoolUsage=52
QuotaPeakPagedPoolUsage=697
ReadOperationCount=6138
ReadTransferCount=12262471
SessionId=1
Status=
TerminationDate=
ThreadCount=16
UserModeTime=286417836
VirtualSize=425541632
WindowsVersion=6.1.7601
WorkingSetSize=119992320
WriteOperationCount=559
WriteTransferCount=198585
 楼主| 发表于 2014-11-24 14:50:29 | 显示全部楼层
回复 4# DAIC

3Q,在你的指导下,我明白怎么结束进程了   已经成功完成任务了
发表于 2014-11-24 21:26:15 | 显示全部楼层
回复 6# wushui


    代码发出来给大家分享一下吧,也许有别人也会需要这个功能。
发表于 2014-11-24 22:57:13 | 显示全部楼层
  1. wmic process where name="a.exe" get commandline,processid|findstr /rc:" -.*"
复制代码
发表于 2014-11-24 23:43:16 | 显示全部楼层
回复 8# amwfjhh


where 支持 and 和 like
  1. wmic process where "name='a.exe' and commandline like '% -aaa%'" call Terminate
复制代码
发表于 2014-11-24 23:57:30 | 显示全部楼层
回复 9# CrLf


    我原想的是后边参数为非固定值,这样的话可以由输入映像命来取得带参进程,继而关闭之。
发表于 2014-11-25 00:05:08 | 显示全部楼层
回复 10# amwfjhh



不过仔细想了下,我们的代码都有不严谨的地方,假如那个 a.exe 的路径是 c:\测试 -aaa\a.exe
卧槽想到这里整个人都不好了,不要说sb才这么命名,我就这么干过
发表于 2014-11-25 00:11:52 | 显示全部楼层
如果进程有先后顺序的话,也可以用 CreationDate 来区分
还有个不太靠谱的办法是按 pid 猜测,一般来说(一般来说!)后出现的进程 pid 值往往比前辈大
以前不小心运行了几次相同的 vbs,要只留最新的一个,没辙的时候就是这么蒙的
发表于 2014-11-25 00:13:26 | 显示全部楼层
这个貌似可以在搜寻正则里把映像名加上。
发表于 2014-11-25 00:49:56 | 显示全部楼层
回复 13# amwfjhh


    好吧,那我就再恶心点:
  1. start "一个恶心的例子" "c:\a.exe -aaa\a.exe"
复制代码
发表于 2014-11-25 01:26:40 | 显示全部楼层
本帖最后由 amwfjhh 于 2014-11-25 11:45 编辑

好吧,这个够恶心
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-20 13:41 , Processed in 0.013301 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表