Re: Scheduling task with other account rather than LOCALSYSTEM by Eduardo
Eduardo
Thu Oct 07 16:21:01 CDT 2004
I´m viewing that you are using the at command instead the WMI class/method.
This is very useful for me, but , only one question more, wath are yoy saying
about taskscheduler.dll
"Jason Stanley" wrote:
> This should get you going. I think you have to register taskscheduler.dll
> for it to work.
>
> TimeToRun="18:55"
> Dayoftheweek="Sunday"
> 'CommandtoRun="\\usatas1s\scrub\20clicln.bat /SCRUB"
> CommandtoRun="\\fca1\scripts\VBScripts\Tivoli\removetivoli.vbs"
>
>
> Const ForReading = 1
> Const ForWriting = 2
> Const ForAppending = 8
>
> SuccessFile="Success.txt"
> BadFile="Bad.txt"
> Set theArgs=WScript.Arguments
> Domain=theArgs.item(0)
> ServiceAccount=theArgs.item(1)
> Password=theArgs.item(2)
>
> Dim objSubKey
> Dim objRegRootKey
> Dim objRemoteRegistry
>
> 'Successful Password Resets
> Set fsGood=CreateObject("Scripting.FileSystemObject")
> Set Success=fsGood.OpenTextFile(SuccessFile, ForWriting, True)
>
> 'Failed Password Resets
> Set fsBad=CreateObject("Scripting.FileSystemObject")
> Set Bad=fsBad.OpenTextFile(BadFile, ForWriting, True)
>
>
> Set oFSO = CreateObject("Scripting.FileSystemObject")
> Set oTextStream = oFSO.OpenTextFile("srvlist.txt")
> x=0
> Do While oTextStream.AtEndOfStream <> TRUE
> Redim Preserve aSrvlist(x)
> strServer = oTextStream.ReadLine
> aSrvlist(x)=RTrim(strServer)
> x=x+1
> Loop
> oTextStream.Close
>
>
>
>
> Set Registry = CreateObject("RegObj.Registry")
>
>
> For Each Server in aSrvlist
> Wscript.echo Server
> Scheduler(CommandtoRun)
> Account=Domain & "\" & ServiceAccount
> Domain=UCase(Domain)
> ServiceAccount=UCase(ServiceAccount)
> SetTasks()
> Next
>
>
>
>
> Sub Scheduler (Path)
> Set ws=Wscript.CreateObject("WScript.Shell")
> 'Commandline="at \\" & Server & " " & TimeToRun & " /Next:" + Dayoftheweek+
> " " + Chr(34)+ Path + Chr(34)
> Commandline="at \\" & Server & " " & TimeToRun & " /Next:" + Dayoftheweek+
> " " + Path
> Wscript.echo Commandline
> ret=ws.Run(Commandline,0, "TRUE")
> If(ret=0) Then
> Wscript.echo "Task Scheduled Successfully " & Server
> Success.WriteLine "Task Scheduled Successfully " & Server
> Else
> Wscript.echo "Task Failed " & Server
> Bad.WriteLine "Task Failed " & Server
> End If
> End Sub
>
>
> Sub SetTasks
> On Error Resume Next
> Set MyTasks = Wscript.CreateObject("Scheduler.SchedulingAgent.1")
> Wscript.echo "Running setTasks against " & Server
> UNCServer="\\"&Server
> MyTasks.TargetComputer="" &UNCServer & ""
> If (Err.Number <>0) Then
> Exit Sub
> End If
> Err.Clear
> For Each objTask in MyTasks.Tasks
> servacct=UCase(objTask.AccountName)
> If (IsNull(servacct)) Then
> objTask.SetAccountInformation Account,Password
> If (Err.Number <> 0) Then
> If(UCase(objTask.JobName) <>UCase("Calculator.job")) Then
> Bad.WriteLine objTask.JobName & "Error Number" & Err.Number & Chr(13)
> & Err.Description
> wscript.echo Server & objTask.JobName & "Error Number" & Err.Number &
> Chr(13) & Err.Description
> Else
>
> End If
> Else
> Success.WriteLine MyTasks.TargetComputer & ":" & objTask.JobName & ":OK"
> Wscript.echo MyTasks.TargetComputer & ":" & objTask.JobName & ":OK"
> End If
> Else
> Xtra.WriteLine "\\" & Server & ":" & objTask.JobName & ":" &
> objTask.AccountName
> Wscript.echo "\\" & Server & ":" & objTask.JobName & ":" &
> objTask.AccountName
> End If
>
> Next
>
>
>
>
> End Sub
> "Eduardo Martin (Spain)" <Eduardo Martin (Spain)@discussions.microsoft.com>
> wrote in message news:471A2180-C8ED-4AF5-B54C-7BF2C9AEB762@microsoft.com...
> > Hello to all,
> >
> > i´m developing a script using the clas Win32_ScheduledJob. The method
> > create
> > of this class allow create Scheduled task in a machine, but, always under
> > the
> > account LOCALSYSTEM adn also this Scheduled task cannot be modified later.
> >
> > Can anyone help me??
> >
> > Thanks in advanced
>
>
>