Page 1 of 1 1
Topic Options
#179399 - 2007-08-16 06:15 PM My KIX works, my COM call does not...HELP!
MACE Offline
Starting to like KiXtart

Registered: 2004-09-07
Posts: 150
Loc: Manchester UK
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)

Top
#179408 - 2007-08-16 10:13 PM Re: My KIX works, my COM call does not...HELP! [Re: MACE]
MACE Offline
Starting to like KiXtart

Registered: 2004-09-07
Posts: 150
Loc: Manchester UK
managed to get the BIAS working... Still don't appear to be creating scheduled task.... HELP!
Even tried shelling an AT command instead but it runs wkix32.exe but it appears to be doing nothing and is not queriable.
 Code:
$ = Scheduleit("notepad.exe",,,,,,"Y")
? "PRESS A KEY TO EXIT"
get $ ;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
;debug on
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

 $WMIService = GetObject("winmgmts:\\" + $Comp + "\root\cimv2")
 ; http://msdn2.microsoft.com/en-us/library/aa394498.aspx
 $colItems = $WMIService.ExecQuery("Select * from Win32_TimeZone",,48)
 For each $objItem in $colItems
  $X = val($objItem.Bias)
  Select
  CASE $X = 0
   $Bias = '-000'
  CASE $X < 0
   $BIAS = '-' + right('00' + cstr(-1 * $X),3)
  CASE $X > 0
   $BIAS = '+' + right('00' + cstr($X),3)
  EndSelect
 Next
; http://msdn2.microsoft.com/en-us/library/aa389389.aspx
 $NewJob = $WMIService.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-24 12:22 PM)

Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1539 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.054 seconds in which 0.025 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org