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?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jacques Bourgeois (James Burger)PresidentCommented:
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.
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
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).
celticianAuthor Commented:
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:

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)

                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)
	wshShell.Run "cmd /k C:\pskill.exe -accepteula dllhost.exe", 1, True	
    end if

Open in new window

Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Jacques Bourgeois (James Burger)PresidentCommented:
Unfortunately, nothing jumps at me when I look at your code.

In your original post, you stated most of the times this script is not being executed, which implies that sometimes, it is. Then, in your second post, you say When executing the script manually it writes the log perfectly. If it works sometimes through the Task Scheduler, did you run it many times in your manual tests? Maybe it runs once but then stops later because of something that happened in the first run.

Also, have you checked the event log? It usually records problems when the Task Scheduler encounters problems with one of its tasks.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
celticianAuthor Commented:
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...
Jacques Bourgeois (James Burger)PresidentCommented:
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows 2000

From novice to tech pro — start learning today.