celtician
asked on
Windows task manager not executing scheduled task correctly?
I have certain visual basic sript that is scheduled to be executed every 10 minutes using windows task manager.
However most of the times this script is not being executed, i don't know why, i have a log that writes everytime the sript is executed and it kills some process (when it doesn't kill it, the log is not being written), so i know that sometiemes the script is executed and kills the process.
however sometimes it needs to kill the process and its not killing it, so i assume the scrip is not being executed
what can be going on here?
i have just added a few new lines so now it writes a log everytime the scrips is invoked, i will know for sure how many times is executed actually and how many its not, but what can be happening?
what should i check?
thanks.
However most of the times this script is not being executed, i don't know why, i have a log that writes everytime the sript is executed and it kills some process (when it doesn't kill it, the log is not being written), so i know that sometiemes the script is executed and kills the process.
however sometimes it needs to kill the process and its not killing it, so i assume the scrip is not being executed
what can be going on here?
i have just added a few new lines so now it writes a log everytime the scrips is invoked, i will know for sure how many times is executed actually and how many its not, but what can be happening?
what should i check?
thanks.
Are you closing your log file? If you don't, the script might hang when you try to open it the following time. If you could post the script we could also be able to see something else.
Did you set up the task to be killed if running for longer than x minutes? If the task runs when being scheduled again, nothing will happen (but an entry in the Scheduled Task log).
ASKER
Jacques: When executing the script manually it writes the log perfectly, but it doesn't when execued by windows task manager. I think its something related to windows task manager rather than the script, anyway il pasting it here as well.
Qlemo: I haven't set up the task to be killed if running for longer than any minutes, i dont think its running at all, as no log is being written... Anyway its a very short task, it wont take any longer than 1-2 seconds at most.
Here is the code:
Qlemo: I haven't set up the task to be killed if running for longer than any minutes, i dont think its running at all, as no log is being written... Anyway its a very short task, it wont take any longer than 1-2 seconds at most.
Here is the code:
Option Explicit
Dim objWMIService, objProcess, objFSO, objTextFile
dim colProcess,colServices, colItems
dim objItem, objService
dim objFSO2, objTextFile2
Dim strComputer, strProcessKill, strProcessMem
Dim memLimit, processMem
Dim mustKill
Dim WshShell
Const ForAppending = 8
Set WshShell = WScript.CreateObject("WScript.Shell")
strComputer = "."
strProcessKill = "'DLLHOST.EXE'"
strProcessMem = "'DLLHOST'"
memLimit = 40000
mustKill = 0
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = " & strProcessKill )
dim intRC
For Each objProcess in colProcess
processMem = objProcess.WorkingSetSize/1024
Set objFSO2 = CreateObject("Scripting.FileSystemObject")
Set objTextFile2 = objFSO2.OpenTextFile ("c:\ejecuciones_dllhost.txt", ForAppending, True)
objTextFile2.WriteLine(now & vbnewline & " Process has been CHECKED with " & processMem & " Kb" & vbnewline & vbNewLine)
objTextFile2.Close
If processMem >= memLimit Then
mustKill = 1
End If
if mustKill = 1 then
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile ("c:\informe_dllhost.txt", ForAppending, True)
objTextFile.WriteLine(now & vbnewline & " Process has been killed with " & processMem & " Kb" & vbnewline & vbNewLine)
objTextFile.Close
wshShell.Run "cmd /k C:\pskill.exe -accepteula dllhost.exe", 1, True
WScript.Quit
end if
Next
WScript.Quit
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I have checked, and im sure the error has nothing to do with the code, but with the OS itself or the task manager... I have run it again...
Thanks for the points, but im sure the error has nothing to do with the code, but with the OS itself or the task manager. is a strong statement. Why? Is this only a feeling? Feelings are often OK in life, but are often wrong when debugging.
Unless you can explain why you are sure, this kind of thinking is the best way to go round and round around a problem. You cannot exclude something unless you can explain why.
Unless you can explain why you are sure, this kind of thinking is the best way to go round and round around a problem. You cannot exclude something unless you can explain why.