金蚕丝雨哪集说被下药:监视进程的批处理

来源:百度文库 编辑:九乡新闻网 时间:2024/04/27 05:26:32

要求:1。后台执行,2。发现此进程结束后立即重起或关机。3。此批处理由服务器调用执行

补充一下:是没有发现此进程就关机,不是发现这个进程就关机,而且我需要能在批处理里设置这个进程的绝对路径(因为在进程中有两个这样的进程,我需要结束其中一个)

代码:

@pv -r0 -d1000 进程>nul 2>nul&&shutdown -s -t 10借助第三方工具pv.exe,每1秒钟检测一次,检测到之后提示10秒后关机。
pv.exe:http://bbs.bathome.net/thread-1864-1-1.html

我qq硬盘里面有下载

简单把pusofalse的命令简单讲一下。

代码:
@pv -r0 -d 1000 进程 >Nul 2>Nul && shutdown -s -t 10

先讲简单的 &&的意思是若成功,就是前面的命令执行成功就 shutdown -s -t 10 就疯狂10秒关机。
@的意思是屏蔽 回显,就是不显示那些杂七杂八的命令行。

pv -r 的意思是 : r 的意思就是repeat ,重复的意思,就是让pv一直重复的在进程中进行检索。

pv -r0 先讲0 ,0跟在pv后面,意思是原文是process found,就是发现了进程,这里的意思就是找到了某个进程的意思。嘿嘿。
那么pv -r0 的意思是  -------重复的去找到某个进程.

pv -d    -d的意思是delay,学过英语的人都知道delay是延时的意思,后面跟毫秒单位 。1000毫秒,等于 1秒,就是每1 秒钟重复一次 去找某个进程。后面跟一个进程名字。例如explorer.exe等等,如果你的收费端是pubwinclient.exe ,就跟到后面就可以了
  
综合起来分析一下。 ^_^
可以这样理解
每一秒钟重复的去发现某个进程,如果真的发现了(执行成功了)就执行 shutdown -s -t  关机命令。

复制内容到剪贴板
代码:
pv -r0 -d 1000 pubwinclient.exe && shutdown -s -t 10

==================================================================

如果没有发现XX进程,则启动XX程序

pv xx.exe 2>nul||start "" "a.exe"
代码:
@echo off
for /l %%a in (1 0 1) do (
     pv a.exe 2>nul||start "" "a.exe"
     pv -r0 -d1000 -x a.exe 2>nul
)
示例:火车经常自动退出,挂机时候用得到。@echo off
@for /l %%a in (1 0 1) do (
     pv LocoySpider.exe 2>nul||start "" "C:\Documents and Settings\Administrator\桌面\火车\火车头采集器\LocoySpider.exe"
     @pv -r0 -d1000 -x LocoySpider.exe 2>nul
)
先检测a.exe是否运行,若无,则运行a,exe。若有,继续向下执行:

pv -r0 -d1000 -x a.exe 2>nul
-d1000: 每1000ms检测一次a.exe
-x 等待程序结束: 若发现a.exe运行中,则继续循环检测,一直到a.exe被结束才执行下面的语句goto loop
代码:
Modes:
  -s       --summary   show usage for the specified MODULE
  -h,-?    --help      display this help information
Actions:
  -k       --kill      kill process
  -a       --activate  brings process main window in the foreground
  -c       --close     close (send WM_CLOSE) to the PROCESS
  -p[nihr] --priority  set priority to "Normal", "Idle", "High", "Real Time"
    [ba]               "Below Normal" and "Above Normal" only on W2K or higher
Output Options:
  -e,      --extend    show additional information if available
  -l,      --long      show command line (can also be a filter)
  -q,      --quiet     supress headers and produce a tab-separated list
  -b       --bare      show process ID only ()
Input Options:
  -f,      --force     never prompt
  -i,      --id        use process ID instead of the PROCESS name
Filters:
  -l[mask] --long      include processes with command line matching mask
  -w[mask] --window    show processes with visible windows matching mask,
                       -e includes in search also invisible windows
  -u[mask] --usage     show processes using modules that matches mask
  -t[root] --tree      display process tree starting starting from the root
Extra Information Options:
  -g       --getenv    get startup environment for the  PROCESS
  -m       --module    show modules used by specified PROCESS
Execution Options:
  -d[time] --delay     delay time in milliseconds before executing command
  -r[err]  --repeat    repeat command in a cycle, while (%ERRORLEVEL% > err)
  -n       --number    %ERRORLEVEL% = negated number of matched processes
  -x[a]    --exit      wait for the process completion (exit)
                        'a' flag waits for all processes, -d sets time-out
  -@[file_name]        read arguments from specified file or from
                       standard input after processing the command line
Arguments can contain '*' and '?' wildcards.
Use return code (%ERRORLEVEL%) in batch files:
    0 - process found (negated number of processes if -n is specified)
    1 - empty result set, 2 - programm error
Examples:
  pv myprocess.exe        get process ID for myprocess.exe.
  pv -e                   get extended list of running processes.
  pv -k sleep*            kill all processes starting with "sleep"
  pv -m -e explorer.exe   get extended information about explorer's modules
  pv -u oleaut*.dll       list of all processes that use matching dll
  pv -ph w*.exe           set priority to hight for all matching processes
  pv explorer.exe -l"*/S" looks for explorer process with /S switch
  pv -r0 -d2000 calc.exe "2>nul" checks every 2 seconds if calc.exe is running
 需要将pv。exe复制到windows/sytem32与cmd同一个文件件