No announcement yet.

w2k3 - adding tasks to the scheduler via group policy

  • Filter
  • Time
  • Show
Clear All
new posts

  • w2k3 - adding tasks to the scheduler via group policy

    I need to schedule a task to run a backup script on each workstation on my domain and I want to use GPO.
    I can't find any doc for this.
    Does anybody have succed doing this or can direct me to the right direction?
    Thank you, Rene

  • #2
    Re: w2k3 - adding tasks to the scheduler via group policy

    You can use a GPO with a login script to create the scheduled task.
    type SCHTASKS /Create at the command promt for more info.


    • #3
      Re: w2k3 - adding tasks to the scheduler via group policy

      Originally posted by martin77 View Post
      You can use a GPO with a login script to create the scheduled task.
      type SCHTASKS /Create at the command promt for more info.
      thank you, but i don't want this to happen at logon/logoff. I want to run the schtask at a specific time during the day...
      Any idea?
      Thanks much, Rene


      • #4
        Re: w2k3 - adding tasks to the scheduler via group policy

        I just ran schtasks /create /? and it gave me loads of useful info that says how to do it.
        Best wishes,
        MCP:Server 2003; MCITP:Server 2008; MCTS: SBS2008


        • #5
          Re: w2k3 - adding tasks to the scheduler via group policy

          Using the logonscript is just a way to run a SCHTASKS.exe command-line on every computer. Logonscripts are being executed via a GPO.

          A SCHTASKS.exe command-line will add a new Job to the Windows Task scheduler. With the command-line you can decide what time the job must be executed during the day.
          It is better to create a run 'ONCE' job, otherwise at every logon an other instance of the same job will be created, that would be to much for the computer. (EDIT: You can provide a 'taskname' so at every logon the old task will be overwritten, but... this is not happen silently).
          The user must be a member of the local administrators group! so you can run the job as a Systemaccount, otherwise the user will always be asked for a password (and the backup will start with only the rights of the user).

          An other way is to use a Computer Startup script instead to schedule the backup task. The command will then be runned as the computer\system account (not by the user like in the previous option).
          Instead of SCHTASKS.exe you can also use a vbscript. When this vbscript is started it first delete previous scripted jobs (scripted jobs only) from the task scheduler, then adds a new Job. With this last method it is no problem when the user did not logged-off the last time, or took the computer home for a day, The job will alway run.

          A third option is to run from a server the SCHTASKS command-line with the /s switch, or if you don't want to create a run-ONCE job (see first option above for an explanation on this) then use a vbScript.
          With this option, the command-line (or the vbscript) can only add the Task to the scheduler on the remote computers that are currently loggon to the domain. The bennefit here is that you can use safely any alternate credentials.


          ' Run this vbscript as a Start-up script for computers.
          ' Or, you can also run this script periodically from
          ' a server by choosing the target computers
          ' for the "strComputer" variable
          '// Author :  Remco Simons [NL] 2007
          '// ( )
          '*** DaysOfWeek ***
          '(used only when RunRepeatedly )
          Const  Monday    = 1
          Const  Tuesday   = 2
          Const  Wednesday = 4
          Const  Thursday  = 8
          Const  Friday    = 16
          Const  Saturday  = 32
          Const  Sunday    = 64
          '*** DaysOfMonth ***
          '(used only when RunRepeatedly )
          Const  Day_1  = 1
          Const  Day_2  = 2
          Const  Day_3  = 4
          Const  Day_4  = 8
          Const  Day_5  = 16
          Const  Day_6  = 32
          Const  Day_7  = 64
          Const  Day_8  = 128
          Const  Day_9  = 256
          Const  Day_10 = 512
          Const  Day_11 = 1024
          Const  Day_12 = 2048
          Const  Day_13 = 4096
          Const  Day_14 = 8192
          Const  Day_15 = 16364
          Const  Day_16 = 32768
          Const  Day_17 = 65536
          Const  Day_18 = 131072
          Const  Day_19 = 262144
          Const  Day_20 = 524288
          Const  Day_21 = 1048576
          Const  Day_22 = 2097152
          Const  Day_23 = 4194304
          Const  Day_24 = 8388608
          Const  Day_25 = 16777216
          Const  Day_26 = 33554432
          Const  Day_27 = 67108864
          Const  Day_28 = 134217728
          Const  Day_29 = 268435456
          Const  Day_30 = 536870912
          Const  Day_31 = 1073741824
          'Schedules Notepad on the target computer ( "." = local)
          'to run at 12:30 PM every Monday, Wednesday, and Friday.
          strComputer         = "."
          strCommand          = "Notepad.exe"          '(include parameters)
          startTime           = "12:30"                '(hh:mm = 24h-notation!)
          InteractWithDesktop = False
           DaysOfWeek         = Monday OR Wednesday OR Friday 
           DaysOfMonth        = Empty                  '(Use 'OR' to select more days)
          Set objWMIService = GetObject("winmgmts:" _
               & "{impersonationLevel=impersonate}!" _
               & "\\" & strComputer & "\root\cimv2")
          'Delete all previous scripted "AT_jobs"
          Set colScheduledJobs = objWMIService.ExecQuery _
              ("Select * from Win32_ScheduledJob")'.AT_Jobs
          For Each objJob in colScheduledJobs
             err = objJob.Delete
          'Create a new AT_Job (AT1)
          Set objNewJob = objWMIService.Get("Win32_ScheduledJob")
          If Not CBool(Len(DaysOfWeek & DaysOfMonth)) Then _
          RunRepeatedly = False Else RunRepeatedly = True
          sBIAS = GetBIAS()
          errJobCreated = objNewJob.Create _
             (strCommand, _
             "********" & Replace(startTime,":", "") &"00.000000" & sBIAS, _
             RunRepeatedly, DaysOfWeek, DaysOfMonth, InteractWithDesktop, _
          Function GetBIAS() 'from the initiating computer !!!
            'Set objSWbemServices
            With GetObject("winmgmts:" _
                 & "{impersonationLevel=impersonate}!" _
                 & "\root\cimv2")
              Set colComputer = .ExecQuery _
                 ("SELECT CurrentTimeZone FROM Win32_ComputerSystem")
            End With
            For Each objComputer in colComputer
              GetBIAS = objComputer.CurrentTimeZone
              Exit For
            If Int(instr(Cstr(GetBIAS),"-"))=1 Then a="-" Else a="+"
            GetBIAS = a & Right(1000 + Abs(GetBIAS),3)
          End Function
          Last edited by Rems; 28th September 2007, 14:13. Reason: added the 'Const' values

          This posting is provided "AS IS" with no warranties, and confers no rights.


          ** Remember to give credit where credit's due **
          and leave Reputation Points for meaningful posts