Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Schtasks

Status
Not open for further replies.

flushie86

IS-IT--Management
Aug 11, 2004
17
0
0
US
I've had so much luck here with the last few questions I had to ask one more. After using the schtasks.exe command to create tasks I would like to setup a way to check and make sure the task was scheduled, however, all I can find is way to show the tasks setup with the AT command. This is an old command and since I'm only dealing with XP and newer systems, i don't need it. Is there a way to interact with the tasks without using the "schtasks /Query" command?
 
Why don't you want to use /Query ?

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
with the /Query I can not specify the task name I am looking for, as to produce a yes or no, I would have to setup a search through the /Query for my task, so I would prefer not to use it.
 
...but /query can display a list or table with the task name in it and you can check for this from within a script if you use the Exec method of WSHShell

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Code:
Option Explicit

Main()

Sub Main()
	Dim objShell : Set objShell = CreateObject("WScript.Shell")
	Dim strOutput : strOutput = objShell.Exec("schtasks /query /fo list").StdOut.ReadAll
	
	WScript.Echo strOutput
	WScript.Echo String(50, "=")
	
	' if you want to parse just the task name out you can use
	' regular expression to accomplish this
	Dim RegEx : Set RegEx = New RegExp
	RegEx.Pattern = "TaskName:\s+(.+)"
	RegEx.IgnoreCase = True
	RegEx.Global = True
	
	If RegEx.Test(strOutput) Then
		Dim colMatches : Set colMatches = RegEx.Execute(strOutput)
		Dim objMatch
		For Each objMatch In colMatches
			WScript.Echo objMatch.SubMatches(0) ' echo just the task name
		Next
	End If
End Sub

You can change the regular expression pattern to be more specific and simply use the Test method of it.... or like I stated previously just use the InStr function....I think using /QUERY is the way to go

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
You can also export to csv format with "/fo csv", then parse that data. In scripting there is always more than one way to do things.

Just a safety note for your parser, XP outputs less columns than 2003 when using the verbose option (/v). I had to learn the hard way when building an audit script.

PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top