本来一直在用tasklist来检查一个进程是不是在运行的但是后来发现,如果是另外一个folder下面在运行,但是你要检测的那个没有运行呢?
只是单纯的获取进程在运行根本不管用,还必须要搞到进程的路径,确定是自己这里的在运行才行。
搜索了好久终于找到了个wmic命令,太强大了……
比如获取指定进程的路径命令:
C:/Documents and Settings/user>wmic process where name="qq.exe" get executablepath
ExecutablePath
F:/Program Files/Tencent/QQ2009/Bin/QQ.exe
以下为从各个地方搜刮来的
更多的可以去看官方帮助文档
另外推荐一个博客上面有很多信息
http://jiayu.blog.51cto.com/121732/22640
------------------------------------------------------------------------
process 进程管理工具
示例:
1.列举当前的进程、进程路径、命令行、进程ID、父进程ID、线程数,内存使用
::wmic process get name,executablepath,commandline,processid,parentprocessid,threadcount,workingsetsize/value
2.列出进程notepad.exe的详细信息
::wmic process where name="notepad.exe" get /format:value
结果如下:
Caption=notepad.exe
CommandLine="C:/WINDOWS/system32/NOTEPAD.EXE" F:/limin文档/WMIC/新建 文本文档.txt
CreationClassName=Win32_Process
CreationDate=20100429202435.656250+480
CSCreationClassName=Win32_ComputerSystem
CSName=20090621-1240
Description=notepad.exe
ExecutablePath=C:/WINDOWS/system32/NOTEPAD.EXE
ExecutionState=
Handle=3864
HandleCount=61
InstallDate=
KernelModeTime=12656250
MaximumWorkingSetSize=1413120
MinimumWorkingSetSize=204800
Name=notepad.exe
OSCreationClassName=Win32_OperatingSystem
OSName=Microsoft Windows XP Professional|C:/WINDOWS|
OtherOperationCount=9403
OtherTransferCount=226934
PageFaults=6341
PageFileUsage=2465792
ParentProcessId=1020
PeakPageFileUsage=2465792
PeakVirtualSize=43327488
PeakWorkingSetSize=6189056
Priority=8
PrivatePageCount=2465792
ProcessId=3864
QuotaNonPagedPoolUsage=5840
QuotaPagedPoolUsage=79436
QuotaPeakNonPagedPoolUsage=6784
QuotaPeakPagedPoolUsage=80428
ReadOperationCount=7
ReadTransferCount=31041
SessionId=0
Status=
TerminationDate=
ThreadCount=1
UserModeTime=3125000
VirtualSize=43327488
WindowsVersion=5.1.2600
WorkingSetSize=2990080
WriteOperationCount=3
WriteTransferCount=216
3.结束指定的进程
一示例:
结束进程CBTray.exe
::wmic process where name="CBTray.exe" call terminate
示例二:
结束进程ID为1020的进程
::wmic process where processid=1020 call terminate
4.创建进程
创建notepad进程
::wmic process call create "c:/windows/notepad.exe"
-------------------------------------------------------------------------------------
1. 查看进程详细信息,这个命令会显示进程的很多信息
wmic process where name="javaw.exe" get /format:value
2. 指定显示某些列,可根据上面命令有选择的显示某些字段
wmic process where name="javaw.exe" get CommandLine,ProcessId
--------------------------------------------------------------------------------------------
Windows WMIC命令详解
【例】将当前系统BIOS,CPU,主板等信息输出到一个HTML网页文件,命令如下:
::得到系统信息.bat,运行bat文件即可
::系统信息输出到HTML文件,查看帮助: wmic /?
::wmic [系统参数名] list [brief|full] /format:hform >|>> [文件名]
wmic bios list brief /format:hform > PCinfo.html
wmic baseboard list brief /format:hform >>PCinfo.html
wmic cpu list full /format:hform >>PCinfo.html
wmic os list full /format:hform >>PCinfo.html
wmic computersystem list brief /format:hform >>PCinfo.html
wmic diskdrive list full /format:hform >>PCinfo.html
wmic memlogical list full /format:hform >>PCinfo.html
PCinfo.html
WMIC命令参数帮助参考:
ALIAS - 访问本地机器上的别名