用vbs后台运行多个bat脚本,如何区分对应进程?

RT,我需要同时运行多个bat脚本,但不想桌面开很多黑色窗口,于是想用vbs把bat脚本转为后台运行。但我有时需要重启某个脚本,而进程里bat的脚本好像名称都是cmd.exe,如果每次都全部关闭再打开觉得不是很好。请问vbs能否自定义进程中的显示名,或者是否有其他办法能后台运行多个bat并能识别不同的脚本?

是不知道重启哪个么?

可以先把你的这些bat代码做些标记,例如给bat每个程序都加上不同标题,再然后用vbs去识别这些标题,从而区分哪个是你需要重启的程序追问

重启某个bat时,先要结束对应的后台正在运行的bat,而后台每个bat的脚本,进程名都是cmd.exe,所以问题是如何在后台运行的bat中做识别,能否自定义进程名而不是统一的cmd.exe呢

追答dim count,program_list(),wsc
set wsc=createobject("wscript.shell")
 program_run("cmd") '隐藏运行. 这条指令每执行一次都会记下一个标识用program_list来获取,例如运行3次后标识为0,1,2
program_run("cmd")
program_run("cmd") 
'这些标识代表进程的pid值
taskkill program_list(0) '根据pid值结束指定进程
taskkill program_list(1)
taskkill program_list(2)
set wsc=nothing 
function tasklist(byval name)
 dim list
 set wmi=getobject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2").execquery("select * from win32_process")
 for each list In wmi
  if instr(list.name,"cmd")>0 then tasklist=list.processid
 next
 wsc.run "taskkill /f /im wmiprvse.exe",0
 set wmi=nothing
end function
function program_run(byval file)
 wsc.run file,0
 program_run=tasklist(file)
 redim preserve program_list(count)
 program_list(count)=program_run
 count=count+1
end function 

function taskkill(byval name)
 wsc.run "taskkill /pid "&name,0
end function

温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-04-10
最佳答案: 1、原代码shutdown -s -t 10改为如下代码,并另存为D:\run.bat @echo off ping 127.1 -n 10 shutdown -s -f -t 0 2、以下代码另存为xx...
相似回答