[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

windows array

Posted on 2010-09-10
8
Medium Priority
?
445 Views
Last Modified: 2012-05-10
i am trying to create  a very simple array.

i would like to run the command schtasks which will display a list of scheduled tasks output is similar to this

TaskName                             Next Run Time            Status
==================================== ======================== ===============
midborots                            7:00:00 PM, 9/10/2010
midborows01                          7:00:00 PM, 9/10/2010
sbs2003                              7:00:00 PM, 9/10/2010

I then need to pass down the results from the taskname column only and store them in a array.  Appreciate your help.

vbscript or python is fine
0
Comment
Question by:Kylo Ren
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 31

Expert Comment

by:Frosty555
ID: 33650626
Rather than using SCHTASKS, use WMI in vbscript to enumerate the scheduled tasks. You can do anything you like with the data (store it in an array or otherwise) afterwards.

Probably the objJob.Name property, or the objJob.Command property contains that "taskname" data you are looking for.
strComputer = "."
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\"_
    & strComputer & "\root\cimv2")
Set colScheduledJobs = objWMIService.ExecQuery _
    ("Select * from Win32_ScheduledJob")

' Output all of the scheduled tasks on the system

For Each objJob in colScheduledJobs

    Wscript.Echo "Command: " & objJob.Command & VBNewLine _
    & "Days Of Month: " & objJob.DaysOfMonth & VBNewLine _
    & "Days Of Week: " & objJob.DaysOfWeek & VBNewLine _
    & "Description: " & objJob.Description & VBNewLine _
    & "Elapsed Time: " & objJob.ElapsedTime & VBNewLine _
    & "Install Date: " & objJob.InstallDate & VBNewLine _
    & "Interact with Desktop: " _
        & objJob.InteractWithDesktop & VBNewLine _
    & "Job ID: " & objJob.JobId & VBNewLine _
    & "Job Status: " & objJob.JobStatus & VBNewLine _
    & "Name: " & objJob.Name & VBNewLine _
    & "Notify: " & objJob.Notify & VBNewLine _
    & "Owner: " & objJob.Owner & VBNewLine _
    & "Priority: " & objJob.Priority & VBNewLine _
    & "Run Repeatedly: " & objJob.RunRepeatedly & VBNewLine _
    & "Start Time: " & objJob.StartTime & VBNewLine _
    & "Status: " & objJob.Status & VBNewLine _
    & "Time Submitted: " & objJob.TimeSubmitted & VBNewLine _
    & "Until Time: " & objJob.UntilTime
Next

Open in new window

0
 
LVL 65

Expert Comment

by:RobSampson
ID: 33651783
Another way would be to capture the output from SchTasks, and then from each line, take the first 20 or so characters (whatever the fixed with is), and store those....if the WMI doesn't work for you, let me know (but it should, really).

Rob.
0
 
LVL 5

Author Comment

by:Kylo Ren
ID: 33652036
ok i know how get the desired data but how do i store it in a array? thats the part im confused about

the example given by rob is one way to use schtasks output. wmi  is another way to enumerate the scheduled tasks but i need to store the output in array. how do i do that?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 65

Expert Comment

by:RobSampson
ID: 33652058
This shortened WMI version should do it...I'll also provide the command line version.

Rob.
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colScheduledJobs = objWMIService.ExecQuery("Select Name from Win32_ScheduledJob")
strNames = ""
For Each objJob in colScheduledJobs
	MsgBox objJob.Name
	If strNames = "" Then
		strNames = objJob.Name
	Else
		strNames = strNames & ";" & objJob.Name
	End If
Next
arrNames = Split(strNames, ";")
For Each strName In arrNames
	MsgBox strName
Next
MsgBox "Done"

Open in new window

0
 
LVL 65

Expert Comment

by:RobSampson
ID: 33652095
Here is the command line parsing version.

Rob.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
strTempOutputFile = objFSO.GetFolder(Replace(wscript.ScriptFullName, wscript.ScriptName, "")).ShortPath & "TempSchTasksOutput.txt"
Set objShell = CreateObject("WScript.Shell")
objShell.Run "cmd /c schtasks > " & strTempOutputFile, 0, True
Set objTemp = objFSO.OpenTextFile(strTempOutputFile, intForReading, False)
strNames = ""
While Not objTemp.AtEndOfStream
	strLine = Trim(objTemp.ReadLine)
	If strLine <> "" Then
		If Left(strLine, 8) <> "TaskName" And Left(strLine, 8) <> "========" And Left(strLine, 8) <> "Folder: " And Left(strLine, 8) <> "INFO: Th" Then
			If strNames = "" Then
				strNames = Trim(Left(strLine, 40))
			Else
				strNames = strNames & ";" & Trim(Left(strLine, 40))
			End If
		End If
	End If
Wend
objTemp.Close
objFSO.DeleteFile strTempOutputFile, True
arrNames = Split(strNames, ";")
For Each strName In arrNames
	WScript.Echo strName
Next
WScript.Echo "Done"

Open in new window

0
 
LVL 5

Author Comment

by:Kylo Ren
ID: 33652109
when  i run the script all i get is done.

0
 
LVL 65

Expert Comment

by:RobSampson
ID: 33652111
I got the same on Windows 7 with the WMI for some reason....but the command line one worked.

Rob.
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 2000 total points
ID: 33652435
If you're running Vista or Windows 7, you can put this in a batch file
cscript.exe ShowTasks.vbs

and then right click the batch file, and click Run As Administrator.

The query needs administrative rights.

Regards,

Rob.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question