bsharath
asked on
Script that check a schedule task last run time does not work perfect.
Hi,
Script that check a schedule task last run time does not work perfect.
it does work but not for all. I think it works fine for windows 2003 Operating system machines. Not able to figure out i get results as
D559 Yes 0
D254 Yes 0
BV04 Yes 2:00:00 AM, 15/11/2009
But 70% i get 0 instead of dates.
regards
sharath
Script that check a schedule task last run time does not work perfect.
it does work but not for all. I think it works fine for windows 2003 Operating system machines. Not able to figure out i get results as
D559 Yes 0
D254 Yes 0
BV04 Yes 2:00:00 AM, 15/11/2009
But 70% i get 0 instead of dates.
regards
sharath
On Error Resume Next
Set objShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("\\dsm\Logs\ScheduleTask.txt", 8, TRUE)
Set objExecObject = objShell.Exec("cmd /c hostname")
strComputerName = objExecObject.StdOut.ReadLine
Set objExecObject = objShell.Exec("cmd /c schtasks -query -fo csv -v | findstr ""Infected Scan""")
strText = objExecObject.StdOut.ReadAll
If strText = "" Then
objFile.WriteLine strComputerName & vbTab & "No"
Else
auxArr = Split(strText, """,""")
objFile.WriteLine strComputerName & vbTab & "Yes" & vbTab & auxarr(5)
End If
ASKER
Sorry could not follow. Can you give me the full code...
ASKER
Any views...
Referring to netcrafts comment can you supply the debug trace for the run using the following code adaptation.
Chris
Chris
On Error Resume Next
Set objShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("\\dsm\Logs\ScheduleTask.txt", 8, TRUE)
Set objExecObject = objShell.Exec("cmd /c hostname")
strComputerName = objExecObject.StdOut.ReadLine
Set objExecObject = objShell.Exec("cmd /c schtasks -query -fo csv -v | findstr ""Infected Scan""")
strText = objExecObject.StdOut.ReadAll
debug.print ">>>" & strtext & "<<<"
If strText = "" Then
objFile.WriteLine strComputerName & vbTab & "No"
Else
auxArr = Split(strText, """,""")
objFile.WriteLine strComputerName & vbTab & "Yes" & vbTab & auxarr(5)
End If
ASKER
Thanks but still get 0 for some machines.
I think its not working for XP and works for Windows 2003 & Vista
I think its not working for XP and works for Windows 2003 & Vista
I haven't changed the function ... The idea is you supply the line(s) printed to the immediate window in teh VBE for analysis.
Chris
Chris
ASKER
Is this a Excel macro...I was trying as vbs
Any ways i placed it in excel and ran it i got this lines only
>>><<<
Any ways i placed it in excel and ran it i got this lines only
>>><<<
DOes this happen with entries that work like BV04 or the ones that fail?
Chris
Chris
ASKER
Sorry could not follow
Script that check a schedule task last run time does not work perfect.
it does work but not for all. I think it works fine for windows 2003 Operating system machines. Not able to figure out i get results as
D559 Yes 0
D254 Yes 0
BV04 Yes 2:00:00 AM, 15/11/2009
But 70% i get 0 instead of dates.
Run the modified sub to achieve the exact same results .... then goto the immediate window and copy the displayed data there ... presumably three lines of test one for each of D559/D254/BV04
Chris
it does work but not for all. I think it works fine for windows 2003 Operating system machines. Not able to figure out i get results as
D559 Yes 0
D254 Yes 0
BV04 Yes 2:00:00 AM, 15/11/2009
But 70% i get 0 instead of dates.
Run the modified sub to achieve the exact same results .... then goto the immediate window and copy the displayed data there ... presumably three lines of test one for each of D559/D254/BV04
Chris
ASKER
Chris do you mean run this code
ID: 25859243
In an excel Module then place the machine name in the immediate window.?
ID: 25859243
In an excel Module then place the machine name in the immediate window.?
Sort of. Yes run that code instead of the original and as a result of running it an output should appear in the immediate window.
Chris
Chris
ASKER
I get this
-------------------------- -
Microsoft Visual Basic
-------------------------- -
Compile error:
Sub or Function not defined
-------------------------- -
OK Help
-------------------------- -
--------------------------
Microsoft Visual Basic
--------------------------
Compile error:
Sub or Function not defined
--------------------------
OK Help
--------------------------
Ah! ... THe original was a VBS so try this instead for a message box with the output which you'll need to note.
Chris
Chris
On Error Resume Next
Set objShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("\\dsm\Logs\ScheduleTask.txt", 8, TRUE)
Set objExecObject = objShell.Exec("cmd /c hostname")
strComputerName = objExecObject.StdOut.ReadLine
Set objExecObject = objShell.Exec("cmd /c schtasks -query -fo csv -v | findstr ""Infected Scan""")
strText = objExecObject.StdOut.ReadAll
msgbox ">>>" & strtext & "<<<"
If strText = "" Then
objFile.WriteLine strComputerName & vbTab & "No"
Else
auxArr = Split(strText, """,""")
objFile.WriteLine strComputerName & vbTab & "Yes" & vbTab & auxarr(5)
End If
ASKER
I get this vista
-------------------------- -
-------------------------- -
>>>"DE06","\Microsoft\Wind ows Defender\MP Scheduled Scan","11/20/2009 1:55:00 AM","Ready","Interactive/B ackground" ,"11/19/20 09 1:54:59 AM","0","N/A","c:\program files\windows defender\MpCmdRun.exe Scan -RestrictPrivileges","N/A" ,"Schedule d Scan","Enabled","Disabled" ,"No Start On Batteries","SYSTEM","Enabl ed","72:00 :00","Sche duling data is not available in this format.","Daily ","1:55:00 AM","1/1/2000","1/1/2100", "Every 1 day(s)","N/A","Disabled"," Disabled", "Disabled" ,"Disabled "
<<<
-------------------------- -
OK
-------------------------- -
Windows 2003
-------------------------- -
-------------------------- -
>>>"PHOS","Infected Scan","2:00:00 AM, 11/20/2009","","Background only","Never","0","SYSTEM" ,"At 2:00 AM every Mon, Tue, Wed, Thu, Fri, Sat, Sun of every week, starting 11/19/2009","C:\Program Files\Sophos\Sophos Anti-Virus\BackgroundScanC lient.exe {BC5638AB-0830-42EA-92BF-9 6CD2191F98 F}","N/A", "N/A","Ena bled","Wee kly","2:00 :00 AM","11/19/2009","N/A","SU NDAY,MONDA Y,TUESDAY, WEDNESDAY, THURSDAY,F RIDAY,SATU RDAY","N/A ","NT AUTHORITY\SYSTEM","Disable d","72:0", "Disabled" ,"Disabled ","Disable d","Disabl ed","Disab led","No Start On Batteries, Stop On Battery Mode"
<<<
-------------------------- -
OK
-------------------------- -
Windows XP
-------------------------- -
-------------------------- -
>>>"DEV41","Infected Scan","02:00:00, 11/20/2009","","Never","0" ,"SYSTEM", "At 2:00 AM every Mon, Tue, Wed, Thu, Fri, Sat, Sun of every week, starting 11/19/2009","C:\Program Files\Sophos\Sophos Anti-Virus\BackgroundScanC lient.exe {7F625AA5-B31F-4EE3-BAB3-7 A572CFFEF7 A}","N/A", "N/A","Ena bled","Wee kly","02:0 0:00","11/ 19/2009"," N/A","SUND AY,MONDAY, TUESDAY,WE DNESDAY,TH URSDAY,FRI DAY,SATURD AY","N/A", "NT AUTHORITY\SYSTEM","Disable d","72:0", "Disabled" ,"Disabled ","Disable d","Disabl ed","Disab led","Disa bled"
"DEV41","MP Scheduled Scan","01:54:00, 11/20/2009","","Never","0" ,"SYSTEM", "At 1:54 AM every day, starting 11/19/2009","C:\Program Files\Windows Defender\MpCmdRun.exe Scan -RestrictPrivileges","N/A" ,"Schedule d Scan","Enabled","Daily ","01:54:00","11/19/2009", "N/A","Eve ryday","N/ A","NT AUTHORITY\SYSTEM","Disable d","72:0", "Disabled" ,"Disabled ","Disable d","Disabl ed","Disab led","No Start On Batteries"
<<<
-------------------------- -
OK
-------------------------- -
--------------------------
--------------------------
>>>"DE06","\Microsoft\Wind
<<<
--------------------------
OK
--------------------------
Windows 2003
--------------------------
--------------------------
>>>"PHOS","Infected Scan","2:00:00 AM, 11/20/2009","","Background
<<<
--------------------------
OK
--------------------------
Windows XP
--------------------------
--------------------------
>>>"DEV41","Infected Scan","02:00:00, 11/20/2009","","Never","0"
"DEV41","MP Scheduled Scan","01:54:00, 11/20/2009","","Never","0"
<<<
--------------------------
OK
--------------------------
Array element 5 seems to be different across the OS types would be my immediate comment! Personally i'm not adept enough to take it further without a lot of research as it's outside my skills base.
Chris
Chris
Try this as a test.
Post the msgbox contents as you did before, and check the log file to see if the results are correct (verify correct)
This will tell me a few things and how to progress towards solution.
Post the msgbox contents as you did before, and check the log file to see if the results are correct (verify correct)
This will tell me a few things and how to progress towards solution.
On Error Resume Next
Set objShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("\\dsm\Logs\ScheduleTask.txt", 8, TRUE)
Set objExecObject = objShell.Exec("cmd /c hostname")
strComputerName = objExecObject.StdOut.ReadLine
Set objExecObject = objShell.Exec("cmd /c schtasks -query -fo csv -v | findstr ""Infected Scan""")
strText = objExecObject.StdOut.ReadAll
msgbox ">>>" & strtext & "<<<"
If strText = "" Then
objFile.WriteLine strComputerName & vbTab & "No"
Else
auxArr = Split(strText, ",")
objFile.WriteLine strComputerName & vbTab & "Yes" & vbTab & auxarr(3)
End If
Hmm, i think I added one too many.
Change
objFile.WriteLine strComputerName & vbTab & "Yes" & vbTab & auxarr(3)
To
objFile.WriteLine strComputerName & vbTab & "Yes" & vbTab & auxarr(2)
I expect the the XP machine will not be correct, but I will need to know for sure.
Change
objFile.WriteLine strComputerName & vbTab & "Yes" & vbTab & auxarr(3)
To
objFile.WriteLine strComputerName & vbTab & "Yes" & vbTab & auxarr(2)
I expect the the XP machine will not be correct, but I will need to know for sure.
ASKER
I get this
-------------------------- -
-------------------------- -
>>>"IN-01","Infected Scan","2:00:00 AM, 11/26/2009","","Background only","2:00:00 AM, 11/25/2009","0","SYSTEM"," At 2:00 AM every Mon, Tue, Wed, Thu, Fri, Sat, Sun of every week, starting 11/22/2009","C:\Program Files\Sophos\Sophos Anti-Virus\BackgroundScanC lient.exe {63A0F059-D93F-4F12-9ECC-0 1F73208433 0}","N/A", "N/A","Ena bled","Wee kly","2:00 :00 AM","11/22/2009","N/A","SU NDAY,MONDA Y,TUESDAY, WEDNESDAY, THURSDAY,F RIDAY,SATU RDAY","N/A ","NT AUTHORITY\SYSTEM","Disable d","72:0", "Disabled" ,"Disabled ","Disable d","Disabl ed","Disab led","Disa bled"
<<<
-------------------------- -
OK
-------------------------- -
--------------------------
--------------------------
>>>"IN-01","Infected Scan","2:00:00 AM, 11/26/2009","","Background
<<<
--------------------------
OK
--------------------------
For info since as I added earlier I am not aware of SCHTASKS usage and some quick research failed to provide usage information.
I have just plugged the data into a script to analyse and get:
VISTA ELement 5 = "11/19/2009 1:54:59 AM"
2K3 ELement 5 = "Background only"
XP ELement 5 = "Never"
This confirms to me that the returned responses across the operating systems is different since if you expect a date in each instance then in two you are getting a string and thereforer you will need to test the OS to establish which parameter to return.
Chris
I have just plugged the data into a script to analyse and get:
VISTA ELement 5 = "11/19/2009 1:54:59 AM"
2K3 ELement 5 = "Background only"
XP ELement 5 = "Never"
This confirms to me that the returned responses across the operating systems is different since if you expect a date in each instance then in two you are getting a string and thereforer you will need to test the OS to establish which parameter to return.
Chris
It would seem that the response from the XP that returns "Never". Have you verified that on a machine that returns a Negative that it has actually ran before? From all the posts from you with the long strings, the entries that have a "0" in the date returned are the ones that says it "never" has ran.
If it is a 2k3 then should be arr(6) instead of (5)
If it is a 2k3 then should be arr(6) instead of (5)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank U Rob...
Can you post the output you get when you insert between line 12 and 13:
objFile.WriteLine strComputerName & vbTab strText
Maybe there's an extra "," in between...