VBScript *unintentionally* pauses on background - vbscript

For a brief description of the code I have, I want to keep in track a certain app named 'CostX.exe' if it closes and opens and I log it on a file called CostXLog.txt
I keep it on an infinite loop. The problem is, i dont know why but it works for a brief period when Im not doing anything productive, but when I do, the script just pauses or should I say it doesnt work anymore though it still stays in the background.
This should be its desired output.
Opened at: 4/7/2021 9:00:52 AM
Closed at: 4/7/2021 9:07:56 AM
CostX was opened for 7 minutes and 4 seconds.
But when I say I do anything productive, the output stays at
Opened at: 4/7/2021 9:00:52 AM
This is my code
Option Explicit
Const ForReading = 1, ForAppending = 8
Dim i, processName, strComputer
Dim fso, inName, outName, shell, curDir, objWMIService, colProcessList
Set fso = CreateObject("Scripting.FileSystemObject")
Set shell = CreateObject("WScript.Shell")
curDir = shell.CurrentDirectory
outName = curDir & "\CostXLog.txt"
Dim counter1, counter2, initialOpen
Dim minDiff, secDiff
Dim timedate1, timedate2
timedate1 = Date() & " " & Time()
initialOpen = 0
counter1 = 0
counter2 = 1
'msgbox curDir
strComputer = "."
processName = "CostX.exe"
Dim newFile, outputFile
newFile = Not fso.FileExists( outName )
while(true)
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("Select Name from Win32_Process WHERE Name LIKE '" & processName & "%'")
Set outputFile = fso.OpenTextFile( outName, ForAppending, True )
if initialOpen = 0 Then
outputFile.WriteLine "Ignore time after this line"
initialOpen = 1
else
If colProcessList.count>0 then
If counter1 = 0 Then
outputFile.WriteLine "Opened at: " & Date() & " " & Time()
timedate1 = Date() & " " & Time()
counter1 = 1
counter2 = 1
End If
else
If counter2 = 1 Then
outputFile.WriteLine "Closed at: " & Date() & " " & Time()
timedate2 = Date() & " " & Time()
minDiff = DateDiff("s", timedate1, timedate2)/60
secDiff = DateDiff("s", timedate1, timedate2)
outputFile.WriteLine "CostX was opened for " & Fix(minDiff) & " minutes and " & secDiff - (Fix(secDiff/60) * 60) & " seconds."
counter2 = 0
counter1 = 0
End If
End if
End If
outputFile.Close
WScript.Sleep 50
wend
Set objWMIService = Nothing
Set colProcessList = Nothing
PS: I am not a programmer, I have assembled that from many sources in the internet, I do understand a bit, but some of the parts in there, I really dont have any idea, I just know that they work as I want them to. So i guess someone could provide me an idea as to how to keep it running no matter what I do in my computer. Is there anything wrong with what I did in the code?
I have also done a batch script with the same intended purpose, the issue is the same, it was also made with a loop, and it pauses when I am busy working.

Related

.vbs to tell time with Sapi but not interrupt given some open processes

I have composed a .vbs file with near zero knowledge of this coding language (with major code from here and here). I put this together to get my computer to tell me the time every 15 minutes (combined with task scheduler). The trickiest part was to have the script check if zoom was running (as to not interrupt video calls with the speech voice). Now, I would like to take it a step further and check for a second process, Microsoft Teams, for the same reason (to not interrupt video calls). So, I have my basic script copied below. It works for telling time and checking for zoom, but I am unsure how to go about adding "Microsoft Teams" to be checked also.
Dim hour_now, minute_now, speaks, speech
hour_now = hour(time)
minute_now = minute(time)
If minute_now = 0 Then
speaks = "Il est " & hour_now & " heures"
Else
speaks = "Il est " & hour_now & " heures " & minute_now & " minutes"
End If
Set speech = CreateObject("sapi.spvoice")
Dim i
Dim strComputer
Dim FindProc
strComputer = "."
FindProc = "zoom"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("Select Name from Win32_Process WHERE Name LIKE '" & FindProc & "%'")
If colProcessList.count>0 then
'wscript.echo FindProc & " is running"
else
'wscript.echo FindProc & " is not running"
speech.Speak speaks
End if
Set objWMIService = Nothing
Set colProcessList = Nothing
I imagine that I'd need to either set the FindProc object to a list of two and either iterate or have it evaluate all at once. Any help is appreciated. BTW, my computer has a French voice so the telling time is written for French.
Also, if anyone has any ideas as how to set this task up with some kind of off/on button or switch, that could be useful, too.
TIA
The only issue I see with your answer code is that it will fail to say the time if any executable is running that starts with "zoom" or "teams", such as ZoomIt.exe or TeamSpirit.exe. Otherwise, it can all be done with far fewer lines of code. Here's my version:
Set oSapi = CreateObject("sapi.spvoice")
Set oWMI = GetObject("winmgmts://./root/cimv2")
Function ProcessExist(Exe)
On Error Resume Next
Set oProcesses = oWMI.ExecQuery("Select Name from Win32_Process Where Name = '" & Exe & "'")
If oProcesses.Count>0 Then ProcessExist = True Else ProcessExist = False
On Error Goto 0
End Function
If Not ProcessExist("Zoom.exe") And Not ProcessExist("Teams.exe") Then
Speech = "Il est " & hour(time) & " heures "
If minute(time)>0 Then Speech = Speech & minute(time) & " minutes"
oSapi.Speak Speech
End If
Alternate version that checks a list of Exes:
Const ExeList = "Zoom,Teams"
Set oSapi = CreateObject("sapi.spvoice")
Set oWMI = GetObject("winmgmts://./root/cimv2")
Function ProcessExist(Exe)
On Error Resume Next
Set oProcesses = oWMI.ExecQuery("Select Name from Win32_Process Where Name = '" & Exe & "'")
If oProcesses.Count>0 Then ProcessExist = True Else ProcessExist = False
On Error Goto 0
End Function
Function InProcessList()
ArrExe = Split(ExeList,",")
InProcessList = False
For Each Exe In ArrExe
If ProcessExist(Exe & ".exe") Then InProcessList = True
Next
End Function
If Not InProcessList Then
Speech = "Il est " & hour(time) & " heures "
If minute(time)>0 Then Speech = Speech & minute(time) & " minutes"
oSapi.Speak Speech
End If
I figured it out. I am not completely satisfied with the fix, but it works and that's all that really matters.
Thanks to comments on post referencing to For Each loops and with some additional sleuthing, this is what I have.
Dim hour_now
Dim minute_now
Dim speaks
Dim speech
hour_now = hour(time)
minute_now = minute(time)
If minute_now = 0 Then
speaks = "Il est " & hour_now & " heures"
Else
speaks = "Il est " & hour_now & " heures " & minute_now & " minutes"
End If
Set speech = CreateObject("sapi.spvoice")
Dim strComputer
Dim TheseProcs
Dim colProcessList
Dim mycount
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
TheseProcs = Array("zoom", "teams")
mycount = 0
For Each FindProc In TheseProcs
Set colProcessList = objWMIService.ExecQuery _
("Select Name from Win32_Process WHERE Name LIKE '" & FindProc & "%'")
If colProcessList.count>0 Then
'wscript.echo FindProc & " is running"
mycount = mycount + 1
End If
Next
If mycount=0 then
speech.Speak speaks
End if
Set objWMIService = Nothing
Set colProcessList = Nothing
I ran into a couple road blocks, though. Defining the Array() and setting up the For Each loop were straightforward enough. I had difficulty in storing the output within the loop. I tried to first define the colProcessList as an ArrayList then use the colProcessList.Add to combine the results from each iteration, but I kept getting errors thrown that it wasn't allowed for that object (I assume the incompatibility is from the .ExecQuery.). So, then, I brought the colProcessList.count code within the loop and created another variable to track it. After the loop finishes, I then evaluate this object for the speech functionality. I am unsatisfied with this part though as I'm sure there is a better way to capture the output of each iteration. Furthermore, I am not satisfied that the code will execute every iteration, rather than stopping once some condition is met (e.g., mycount>0). I welcome input on these as well as scheduling the task manually with an off/on switch.

VBScript Error - Object Required ObjTSO

'========================================================================
'## Global Object and Variable Settings
'========================================================================
Dim WshShell: Set WshShell = CreateObject("WScript.Shell")
Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim strSystemDrive: strSystemDrive = WshShell.ExpandEnvironmentStrings("%SystemDrive%")
'========================================================================
'## Main Code
'========================================================================
'On Error Resume Next
'---------------------------------------------------------------------------------------------------------------------------
'## Script Variables
'---------------------------------------------------------------------------------------------------------------------------
Dim strFolder: strFolder = strSystemDrive & "\Endpoint Reboot Info"
Dim strFile: strFile = strSystemDrive & "\Endpoint Reboot Info\Endpoint_Reboot_Logfile.txt"
strcurrentDateTime = Now()
Dim string0: string0 = "Endpoint restart analysis initialized"
Dim string1: string1 = "Calculating the endpoint uptime .. If greater than 14 days, machine will be restarted"
Dim string2: string2 = "Warning: The current OS Uptime exceeds 14 days! This system will be rebooted!"
Dim string3: string3 = " As the current OS Uptime is less than 14 days, this system will NOT be rebooted currently"
Dim string4: string4 = "This system will restart now!"
Dim string5: string5 = "User has clicked cancel, hence PC was NOT restarted"
Dim string6: string6 = "User has clicked OK. Restarting PC now.."
'---------------------------------------------------------------------------------------------------------------------------
'## Code for creating the folder and file necessary for logging and initializing the log file
'---------------------------------------------------------------------------------------------------------------------------
Function CreateLogFile(filename)
Dim f: set f = objFSO.OpenTextFile(strFile, 8, True)
f.WriteLine strcurrentDateTime & " " & string0
f.WriteLine strcurrentDateTime & " " & string1
Set CreateLogFile = f
End Function
'---------------------------------------------------------------------------------------------------------------------------
'## Code for checking endpoint OS uptime and force restarting post message display to end user
'---------------------------------------------------------------------------------------------------------------------------
Dim objTSO: Set objTSO = CreateLogFile(strFile)
strComputer = "."
Const FOR_APPENDING = 8
SET objWMIDateTime = CREATEOBJECT("WbemScripting.SWbemDateTime")
SET objWMI = GETOBJECT("winmgmts:\\" & strComputer & "\root\cimv2")
SET colOS = objWMI.InstancesOf("Win32_OperatingSystem")
FOR EACH objOS in colOS
objWMIDateTime.Value = objOS.LastBootUpTime
objTSO.WriteLine "Last Boot Up Time: " & objWMIDateTime.GetVarDate & vbcrlf & _
"System Up Time: " & TimeSpan(objWMIDateTime.GetVarDate,NOW) & _
" (hh:mm:ss)"
NEXT
FUNCTION TimeSpan(dt1, dt2)
' Function to display the difference between
' 2 dates in hh:mm:ss format
IF (ISDATE(dt1) AND ISDATE(dt2)) = FALSE THEN
TimeSpan = "00:00:00"
EXIT FUNCTION
END IF
seconds = ABS(DATEDIFF("S", dt1, dt2))
minutes = seconds \ 60
hours = minutes \ 60
minutes = minutes MOD 60
seconds = seconds MOD 60
IF LEN(hours) = 1 THEN hours = "0" & hours
TimeSpan = hours & ":" & _
RIGHT("00" & minutes, 2) & ":" & _
RIGHT("00" & seconds, 2)
If (hours > 336) Then
f.WriteLine strcurrentDateTime & " " & string2
Dim retval: retval = InputBox("Warning!: The current OS Uptime exceeds 14 days! This system will be rebooted! Please save ALL of your work and ONLY then click OK")
If IsEmpty(retval) Then
msgbox ("User has terminated the action by clicking cancel")
objTSO.WriteLine string5
Else
objTSO.WriteLine string6
WshShell.Run "shutdown.exe -R -T 0"
End If
Else
WScript.Sleep 10000
strcurrentDateTime = Now()
objTSO.WriteLine strcurrentDateTime & string3
WScript.Quit
End If
f.Close()
END FUNCTION
'---------------------------------------------------------------------------------------------------------------------------
'## End of code/VB Script
'---------------------------------------------------------------------------------------------------------------------------
I have now put up the full script as suggested. Please help with below queries:
This Line is not getting written into the log file
objTSO.WriteLine "Last Boot Up Time: " & objWMIDateTime.GetVarDate & vbcrlf & _
"System Up Time: " & TimeSpan(objWMIDateTime.GetVarDate,NOW) & _
" (hh:mm:ss)"
Also please check the logic of the code by changing the (hours>336) condition. This script will be executed locally on the machines, so instead of the previous reboot function, i have now modified it to WshShell.Run "shutdown.exe -R -T 0"
Please guide! Thanks!!
Your function CreateLogFile creates/opens the file, but then closes it right away:
Function CreateLogFile()
If objFSO.FileExists(strFile) Then
Set objTSO = objFSO.OpenTextFile(strFile, FOR_APPENDING)
objTSO.WriteLine strcurrentDateTime & " " & string0
objTSO.WriteLine strcurrentDateTime & " " & string1
objTSO.Close()
Else
objFSO.CreateTextFile(strFile)
Set objTSO = objFSO.OpenTextFile(strFile, FOR_APPENDING)
objTSO.WriteLine strcurrentDateTime & " " & string0
objTSO.WriteLine strcurrentDateTime & " " & string1
objTSO.Close()
End If
End Function
meaning that when the function returns the file handle is already closed, causing all subsequent attempts to write to the file (without opening it again) to fail.
What you actually want to do is change your function to something like this:
Function CreateLogFile(filename)
Dim f : Set f = objFSO.OpenTextFile(filename, 8, True)
f.WriteLine Now & " " & string0
f.WriteLine Now & " " & string1
Set CreateLogFile = f
End Function
Dim objTSO : Set objTSO = CreateLogFile(strFile)
...
objTSO.Close 'at the end of the script
Setting the 3rd parameter of the OpenTextFile method to True causes it to create the file in case it's missing.

VBS process memory consumption growing over time

I have a VBScript that I run with Windows Script Host. The script reads some stuff from a text file and then launches a desktop shortcut every time a file is added to a certain folder. It starts of at 1.4Mb memory and grows every time I add a file to that folder. Is there a way to solve that? If not, I guess I could have a script that periodically kills the first script and relaunches it? Here is the script:
'- 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
EDIT: Added Set object = Nothing. Process is still growing (a little less though). What else can possibly make it grow?
New code:
'- 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

Wait for program to complete

To monitor the bandwidth usage and not to unnecessarily load programs in the start up,I want to execute the dumeter.exe then firefox.exe.When I shutdown firefox it should kill dumeter.I used the following code to start
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "c:\progra~1\dumeter\dumeter.exe"
WshShell.Run "c:\progra~1\mozill~1\firefox.exe
Need to run taskkill only when firefox is closed.Tried using a bat file but sometimes the dumeter starts and closes on its own does not wait.
WshShell.Run "taskkill /f /im dumeter.exe"
Set WshShell = Nothing
You can wait for a process to end by subscribing to the appropriate WMI event. Here's an example:
strComputer = "."
Set oWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
''# Create an event query to be notified within 5 seconds when Firefox is closed
Set colEvents = oWMI.ExecNotificationQuery _
("SELECT * FROM __InstanceDeletionEvent WITHIN 5 " _
& "WHERE TargetInstance ISA 'Win32_Process' " _
& "AND TargetInstance.Name = 'firefox.exe'")
''# Wait until Firefox is closed
Set oEvent = colEvents.NextEvent
More info here: How Can I Start a Process and Then Wait For the Process to End Before Terminating the Script?
Option Explicit
Const PROC_NAME = "<Process_You_Want_to_Check>"
Const SLEEP_INTERVAL_MS = 5000 '5 secs
Dim objWMIService
Dim colProcesses, objProcess, inteproc
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
inteproc = -1 'set in unknown state
Do Until inteproc = 0
Set colProcesses = objWMIService.ExecQuery(_
"Select * from Win32_Process where Name='" & PROC_NAME & "'")
inteproc = colProcesses.count
If inteproc > 0 then
WSCRIPT.ECHO "Process " & PROC_NAME & " is still runing, wait for " & SLEEP_INTERVAL_MS / 1000 & " seconds"
WScript.Sleep(SLEEP_INTERVAL_MS)
else
wscript.echo "Process " & PROC_NAME & " Finished. Continue running scripts"
End If
Loop

VBScript: way to check why the script stopped?

I have this VBScript which runs however, while it is processing, it will randomly stop and require a user to hit the spacebar for it to display the rest of its ongoing output.
How do I figure out why this is happening?
Here is a copy of the script:
'On Error Resume Next
Dim arrFolders()
intSize = 0
Function StampNow()
Dim Hr, Mn, Yr, Mon, Dy, Date1
Date1=Now()
Hr=DatePart("h",Date1)
Mn=DatePart("n",Date1)
Yr = DatePart("yyyy",Date1)
Mon = DatePart("m",Date1)
Dy = DatePart("d",Date1)
StampNow = Yr & "-" & Mon & "-" & Dy
end function
'Output log info.
Function OutputToLog (strToAdd)
Dim strDirectory,strFile,strText, objFile,objFolder,objTextFile,objFSO
strDirectory = "c:\log"
strFile = "\dpadmin_copy2run-"& StampNow & ".bat"
'strText = "dpadmin_copy2"
strText = strToAdd
' Create the File System Object.
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Check that the strDirectory folder exists.
If objFSO.FolderExists(strDirectory) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFolder = objFSO.CreateFolder(strDirectory)
'WScript.Echo "Just created " & strDirectory
End If
If objFSO.FileExists(strDirectory & strFile) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFile = objFSO.CreateTextFile(strDirectory & strFile)
'Wscript.Echo "Just created " & strDirectory & strFile
End If
set objFile = nothing
set objFolder = nothing
' OpenTextFile Method needs a Const value
' ForAppending = 8 ForReading = 1, ForWriting = 2
Const ForAppending = 8
Set objTextFile = objFSO.OpenTextFile _
(strDirectory & strFile, ForAppending, True)
' Writes strText every time you run this VBScript.
objTextFile.WriteLine(strText)
objTextFile.Close
End Function
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
strFolderName = "D:\1\production\Openjobs"
Set colSubfolders = objWMIService.ExecQuery _
("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _
& "Where AssocClass = Win32_Subdirectory " _
& "ResultRole = PartComponent")
dim diffindates
'Init vars for regex.
Dim retVal, retVal2
Dim Lastprop
Dim objRegExpr 'regex variable
Set objRegExpr = New regexp
Set objRegExprX31 = New regexp
objRegExpr.Pattern = "[0-9][0-9][0-9][0-9][0-9][0-9][A-Z][A-Z][A-Z]"
objRegExprX31.Pattern = "[0-9][0-9][0-9][0-9][0-9][0-9]X31"
objRegExpr.Global = True
objRegExprX31.Global = True
objRegExpr.IgnoreCase = True
objRegExprX31.IgnoreCase = True
'Variables for getting last accessed property.
Dim fs, f
Set fs = CreateObject("Scripting.FileSystemObject")
'Current time vars.
Dim currenttime
currenttime = Now()
ParentFolder = "D:\1\Production\Openjobs\ClosedJobs"
For Each objFolder in colSubfolders
intSize = intSize + 1
retVal = objRegExpr.Test(objFolder.Name)
retVal2 = objRegExprX31.Test(objFolder.Name)
if (retVal OR retVal2 ) then
'set filename to array
strFolderName = objFolder.Name
'Get last modified date.
Set f = fs.GetFolder(objFolder.Name)
Lastprop = f.DateLastModified
'MsgBox(Lastprop)
if ( DateDiff("m", f.DateLastModified, Now()) > 4) then
diffindates = DateDiff("m", f.DateLastModified, Now())
Set objShell = CreateObject("Shell.Application")
Set objCopyFolder = objShell.NameSpace(ParentFolder)
OutputToLog("rem " & f.DateLastModified & ":" & objFolder.Name )
outputtolog("move /Y """ & objFolder.Name & """ " & ParentFolder)
wscript.echo(diffindates & ":" & objFolder.Name & vbCr)
end if
end if
Next
Update
It stops at the line:
Set objTextFile = objFSO.OpenTextFile _
(strDirectory & strFile, ForAppending, True)
with the error Microsoft VBScript runtime error: Permission denied
I'm a little confusd by this. The logfile was only 356kb
I was able to run your script several times without it pausing for input. Run your script with the //X flag to start it in the debugger:
>cscript //nologo //X dpadmin_copy2.vbs"
You should be able to then step through the code.
You can also start putting in wscript.echo trace statements everywhere and see if you can narrow down what it's waiting on.
One thing that's gotten me in the past; If your command console is in QuickEdit mode and you accidentally click anywhere in the console window, the console will hang while it waits for you to press a key.
Well the first step is to remove any global On Error Resume Next statements. Better feedback would come if we could see the script.
You usually get an Permission denied when trying to write to a text file when the text file already has an open handle from some other process or because you have previously opened a handle earlier in you code which you have not closed. I haven't tried this but I don't know why this wouldn't work, you can look at using Handle from Sysinternals (Microsoft) to tell you what process has the open handle for the file. Please see here for a further reference of how to use Handle: http://www.orcsweb.com/blog/post/Closing-open-file-handles.aspx You could also write a second script which runs in a loop to monitor the main script. The second script can verify the first script by doing a WMI Process query which returns only processes that match a defined command line. The second script could then restart the main it stops, alert you, log a file, launch a handle search, etc.

Resources