This is my first venture into COM and I need a little help.
1. I am trying to read the BIAS value but not sure why I get nothing.
2. The JobId is defined 'somewhere' but not sure what it should be or from where and I get an invalid handle error when I make the JOB call.
See bottom of the CODE...

 Code:
$ = Scheduleit("notepad.exe",,,,,,"Y")
get $a ;pause

Function SCHEDULEIT($JOB, Optional $DateX, Optional $TIMEX, Optional $Days, Optional $DOM, Optional $Comp, Optional $I)
; Syntax: ref - 
;         http://msdn2.microsoft.com/en-us/library/aa389389.aspx
;         http://msdn2.microsoft.com/en-us/library/aa394399.aspx
; $Job   = Command line string of job to run
; $DateX = YYYYMMDD defaults to Today
; $TimeX = HHMMSS defaults to next minute
; $Days  = "MO,TU,WE,TH,FR,SA,SU" Select 1 or more separated by a comma. Optional !
; $DOM   = String Number 1 to 31 apropriate for day of month. Optional !
; $Comp = Computername or TCP.IPA.DDR.ESS  Nul defaults to the computer running the script.
; $I     = Interact With Desktop. 'TRUE' If NOT Blank, use a Y or similar. Default = FALSE

If $Job = ""
 Exit 0
Endif

Dim $X, $DayX, $DayN, $DM, $RR, $JOBID,$JOBX,$UTCO,$Service,$NewJob,$JobCreated

If $I <> ""
 $I = " TRUE "
Endif

If $DateX = ""
 $DateX = "********"
Endif

If $TimeX = "" or len($TimeX) <> 6
 $TimeX = left(@time,2)+right("0"+cstr(val(substr(@time,4,2))+1),2)+"00"
Endif

If $Comp = ""
  $Comp = "."
Endif

If left($Comp,2) = "\\"
  $Comp = right($Comp,-2)
Endif

If $Days <> ""
 $DayX=SPLIT($Days,',')
 For $X = 0 to Ubound($DayX)
  Select
  Case left($DayX[$x],2) = "MO"
   $DayN = $DayN + '1 OR '
  Case left($DayX[$x],2) = "TU"
   $DayN = $DayN + '2 OR '
  Case left($DayX[$x],2) = "WE"
   $DayN = $DayN + '4 OR '
  Case left($DayX[$x],2) = "TH"
   $DayN = $DayN + '8 OR '
  Case left($DayX[$x],2) = "FR"
   $DayN = $DayN + '16 OR '
  Case left($DayX[$x],2) = "SA"
   $DayN = $DayN + '32 OR '
  Case left($DayX[$x],2) = "SU"
   $DayN = $DayN + '64 OR '
  EndSelect
 Next
 If $DayN <>""
  $DayN = left($DayN,-4) ; Strip off trailing OR
 Endif
 If len($DayN) > 2 ;RunRepeatedly = 'True' for multiple days
  $RR = ' TRUE '
 Endif
Endif

If val($DOM)>0
 $DM=1
 For $X = 2 to val($DOM)
  $DM=$DM+$DM
 Next
 If $DayN <>""
  $DayN = ""
 EndIf
 $RR = ' TRUE '
Endif

; $JOBID = cstr(RND(srnd(9)))
 $Service = GetObject('winmgmts:\\'+$Comp+'root\cimv2')
 $Query = "Select * from Win32_TimeZone"
; http://msdn2.microsoft.com/en-us/library/aa394498.aspx
 $cItems = $Service.ExecQuery($Query)
 For Each $oItem In $cItems
  $BIAS = $oItem.bias
  ? $BIAS
 next
; http://msdn2.microsoft.com/en-us/library/aa389389.aspx
; $BIAS = '-000' ; Default +- Time Offset for region from GMT - UTC

 $NewJob = $Service.Get("Win32_ScheduledJob")
 $JobX = '"'+$Job+'" , "'+$DateX+$TimeX+'.000000'+$BIAS+'",'+$RR+','+$DayN+','+cstr($DM)+','+$i+', JobId'
 $JobCreated = $NewJob.Create($JobX)
 If $JobCreated = 0
  $colItems = $WMIService.ExecQuery("Select * from Win32_ScheduledJob",,48)
  For each $objItem in $colItems
   ? "New Job ID: " + $objItem.JobId
  next
 Else
  ? "An error occurred: " + @serror
 EndIf
EndFunction


Edited by MACE (2007-08-16 10:50 PM)