VBS进程内存消耗随着时间的推移而增长

时间:2017-07-07 13:24:28

标签: vbscript wsh

我有一个使用Windows Script Host运行的VBScript。该脚本从文本文件中读取一些内容,然后在每次将文件添加到某个文件夹时启动桌面快捷方式。它从1.4Mb内存开始,每次我将文件添加到该文件夹​​时都会增长。有办法解决这个问题吗?如果没有,我想我可以有一个脚本定期杀死第一个脚本并重新启动它?这是脚本:

'- Read some stuff from a file
Set f = CreateObject("Scripting.FileSystemObject").OpenTextFile("D:\Post 
Processing Files\Common Files\New Data Folder Watcher\DATA_STORE.txt", 1)
dataStore = replace(f.ReadLine,"Title:","")
f.SkipLine
shortCut = replace(f.ReadLine,"Title:","")
f.Close

strComputer = "."

Set objWMIService = GetObject("winmgmts:" & "
{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colMonitoredEvents = objWMIService.ExecNotificationQuery("SELECT * FROM 
__InstanceCreationEvent WITHIN 5 WHERE "  & "Targetinstance ISA 
'CIM_DirectoryContainsFile' and " & "TargetInstance.GroupComponent= " & 
"'Win32_Directory.Name=" &Chr(34)&  dataStore  &Chr(34)& "'")

Set objShell = CreateObject("Wscript.Shell")

'- Watch
Do

    Set objLatestEvent = colMonitoredEvents.NextEvent
    objLatestEvent.TargetInstance.PartComponent

    objShell.Run shortCut

    '- Delay
    WScript.Sleep 120000

Loop

编辑:添加了Set object = Nothing。流程仍在增长(虽然稍微减少)。还有什么可以让它成长? 新代码:

'- Read some stuff from a file
Set f = CreateObject("Scripting.FileSystemObject").OpenTextFile("D:\Post 
Processing Files\Common Files\New Data Folder Watcher\DATA_STORE.txt", 1)
dataStore = replace(f.ReadLine,"Title:","")
f.SkipLine
shortCut = replace(f.ReadLine,"Title:","")

f.Close
Set f = Nothing

strComputer = "."


' LOOP THROUGH EACH NEWLY ADDED FILE
Do

    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colMonitoredEvents = objWMIService.ExecNotificationQuery("SELECT * FROM __InstanceCreationEvent WITHIN 5 WHERE "  & "Targetinstance ISA 'CIM_DirectoryContainsFile' and " & "TargetInstance.GroupComponent= " & "'Win32_Directory.Name=" &Chr(34)&  dataStore  &Chr(34)& "'")
    Set objLatestEvent = colMonitoredEvents.NextEvent
    Set objShell = CreateObject("Wscript.Shell")

    objLatestEvent.TargetInstance.PartComponent

    objShell.Run shortCut 

    '- Delay
    WScript.Sleep 120000

    '- Clear Memory
    Set  objLatestEvent = Nothing
    Set  objShell = Nothing
    Set  colMonitoredEvents = Nothing
    Set  objWMIService = Nothing


Loop   

0 个答案:

没有答案