VBScript监测进程进行情况。

这篇博客介绍了如何使用VBScript来定时运行一个Exe文件,并确保该程序始终运行。同时,VBScript还会监控并启动未运行的关联进程E1和E2。此外,该脚本还包含了写入日志的功能,记录程序的运行状态。
摘要由CSDN通过智能技术生成
  
有C:/Document1和C:/Document2这样两个文件夹,里面分别有一个相同的Exe文件E1和E2,它的作用是一定被执行就处理该文件夹下的文件。
需求:不可以修改Exe文件,通过一个程序P1来完成:
  1. 定时运行(Exe文件中没有定时功能)。
  2. P1运行,保证E1和E2都要运行,即如果运行了就要保持,如果没有运行的话就要启动Exe。
  3. 写入日志。需要写入如下内容:
------------------------------------------------
Process ID: 3036
Process Path:
Time Created: 2/14/2007 11:04:53 AM
Time Deleted: 2/14/2007 11:05:23 AM
Duration: 30 seconds
------------------------------------------------
      启动了几个就要写入几个。
Note: 进程名称相同,路径不同,不能修改Exe文件。
 
方案:通过一个将一个VBS程序添加到Task Schedule中来定时地执行。通过VBS可以实现对Process的查询,以及对Process的create和delete的情况进行记录。
实现代码如下:
 
On   error   resume   next
' The path of the executable.
'
The first path is as usual.
'
The second path is on the C disk.(You can copy the notepad.exe from system32 and run it.)
Dim  strPath1
Dim  strPath2
' The name of the process.
Dim  strNameOfProcess
' The interval string between different log data.
Dim  strInterval
' An Integer 
'
0 The process don't exists in the Windows Task Manager
'
1 Exist one of two.
'
2 Both exist.
Dim  intWhetherExist
' The path of the process need to be fun.
Dim  strExePath
' The ID of the process need to be fun.
Dim  intExeID
' Save the match relationship between ProcessID and ExecutablePath in this array.
Dim  arrayProcessIDandExecutablePath( 1 1 )
' The path of the log file.
Dim  strLogPath 
' --------------------------------------------------------------------------------
'
Take notepad.exe for example. Open just one notepad.
strPath1  =   " C:WINNTSystem32 otepad.exe "
strPath2 
=   " C: otepad.exe "
strNameOfProcess 
=   " notepad.exe "
strInterval 
=   " ------------------------------------------------ "
strLogPath 
=   " c: estfile.txt "  
' --------------------------------------------------------------------------------
'
Default is zero.
intWhetherExist  =   0
' Create an array contains the name of all processes need to be found.
strComputer  =   " . "
arrTargetProcs 
=   Array (strNameOfProcess)

' ---------------------------------------------------------------
'
1. Find the process we want.
'
---------------------------------------------------------------
'
Find the process in the name list.
Set  objWMIService  =   GetObject ( " winmgmts: "
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值