Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Delete a scheduled task on all machines in a txt file. Scheduled task called "AT01"

Posted on 2009-02-21
11
Medium Priority
?
436 Views
Last Modified: 2012-06-27
Hi,

Delete a scheduled task on all machines in a txt file. Scheduled task called "AT01"
Need to get the success & failure to just know on how many machines it was deleted.

And need to skip ping failure machines permission issu machines.

Regards
Sharath
0
Comment
Question by:bsharath
  • 6
  • 5
11 Comments
 
LVL 14

Accepted Solution

by:
yehudaha earned 2000 total points
ID: 23702077
hey

maybe i still don't control vbscript as i think i am but i don't know any sure way to pull the job name and use it in the script.

so in my script run by job id in you case i guess 1 .
Const ForReading = 1
Const ForWriting = 2
  
Set objfso = CreateObject("Scripting.FileSystemObject")
Set objlist = objfso.OpenTextFile("c:\list.txt", ForReading)
Set objlog = objfso.CreateTextFile("c:\log.txt", ForWriting)
 
Do Until objlist.AtEndOfStream
strComputer = objlist.ReadLine
If Reachable(strcomputer) Then
  If per(strcomputer) then
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
On Error Resume Next    
Set objInstance = objWMIService.Get("Win32_ScheduledJob.JobID=1")
If Err.Number = 0 Then
Err.Clear
On Error Goto 0
err = objInstance.Delete
If InStr(Err,"0") Then
objlog.WriteLine "the job deleted on " & strcomputer
Else
objlog.WriteLine "failed to delete job on " & strcomputer
End If
Else
objlog.WriteLine "the job didn't find on " & strcomputer
End if
Else
objlog.WriteLine "you don't have permission on " & strcomputer
End If
Else
objlog.WriteLine strcomputer & " isn't reachable"
End if
Loop
 
Function Reachable(strComputer)
 
 strCmd = "ping -n 1 " & strComputer
 
 Set objShell = CreateObject("WScript.Shell")
 Set objExec = objShell.Exec(strCmd)
 strTemp = UCase(objExec.StdOut.ReadAll)
 
 If InStr(strTemp, "REPLY FROM") Then
 Reachable = True 
 Else
 Reachable = False
 End If
End Function
 
Function per(computer)
	strcomputer = computer
	On Error Resume Next
	Set objWMIService = GetObject("winmgmts:" _
	& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
	If err.number <> 0 Then
		err.Clear
		per = False
		On Error goto 0
	Else
		per = True
		On Error goto 0
	End If
End Function

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 23702306
Does that mean that all jobs will be deleted. Or do i need to see something in the task and let you know.

Any help on the 2 posts

Add Administrator to each group....
0
 
LVL 11

Author Comment

by:bsharath
ID: 23702307
Does that mean that all jobs will be deleted. Or do i need to see something in the task and let you know.

Any help on the 2 posts

Add Administrator to each group....
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:yehudaha
ID: 23703293
no it mean only at1 will be deleted as you asked

i'm checking now the other posts
0
 
LVL 11

Author Comment

by:bsharath
ID: 23704774
Thanks i think its working.

What is the change i need to do in the script to just log them without deleting.

So i can see if the script is deleting the right one please...
0
 
LVL 11

Author Comment

by:bsharath
ID: 23704775
Thanks i think its working.

What is the change i need to do in the script to just log them without deleting.

So i can see if the script is deleting the right one please...
0
 
LVL 14

Expert Comment

by:yehudaha
ID: 23708826
try this
Const ForReading = 1
Const ForWriting = 2
  
Set objfso = CreateObject("Scripting.FileSystemObject")
Set objlist = objfso.OpenTextFile("c:\list.txt", ForReading)
Set objlog = objfso.CreateTextFile("c:\log.txt", ForWriting)
 
Do Until objlist.AtEndOfStream
strComputer = objlist.ReadLine
If Reachable(strcomputer) Then
  If per(strcomputer) then
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
On Error Resume Next    
Set objInstance = objWMIService.Get("Win32_ScheduledJob.JobID=1")
If Err.Number = 0 Then
Err.Clear
On Error Goto 0
objlog.WriteLine "the job deleted on " & strcomputer
Else
objlog.WriteLine "the job didn't find on " & strcomputer
End if
Else
objlog.WriteLine "you don't have permission on " & strcomputer
End If
Else
objlog.WriteLine strcomputer & " isn't reachable"
End if
Loop
 
Function Reachable(strComputer)
 
 strCmd = "ping -n 1 " & strComputer
 
 Set objShell = CreateObject("WScript.Shell")
 Set objExec = objShell.Exec(strCmd)
 strTemp = UCase(objExec.StdOut.ReadAll)
 
 If InStr(strTemp, "REPLY FROM") Then
 Reachable = True 
 Else
 Reachable = False
 End If
End Function
 
Function per(computer)
        strcomputer = computer
        On Error Resume Next
        Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
        If err.number <> 0 Then
                err.Clear
                per = False
                On Error goto 0
        Else
                per = True
                On Error goto 0
        End If
End Function

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 23708838
How and what does the script delete. why i ask is there are machines that show 10 + scheduled scans as

AT1
AT2
AT3
and so on

Can we set to delete anything with AT


0
 
LVL 14

Expert Comment

by:yehudaha
ID: 23708870
sorry what i tryed with my knowledge it's only the job id

you can live the question open a new one and maybe one of ther other experts can help you
0
 
LVL 11

Author Comment

by:bsharath
ID: 23713636
Thank U
0
 
LVL 14

Expert Comment

by:yehudaha
ID: 23715412
thanks you
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month20 days, 19 hours left to enroll

810 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