Sign in to follow this  
Followers 0
KXM

schtasks COM object, and me

3 posts in this topic

#1 ·  Posted (edited)

So schtasks.exe just isn't cutting it for me any more... I need more power.

But I can't seem to get the syntax quite right:

$oComError_UDFGlobal = ObjEvent("AutoIt.Error", "__Generic_COM_Error")

$strComputer = "."
$objWMIService = ObjCreate("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2") 
$JobID = "Test"
$objNewJob = $objWMIService.Get("Win32_ScheduledJob")

$errJobCreate = $objWMIService.Create ("C:\windows\Notepad.exe", "********143000.000000-420", True , 1 OR 4 OR 16, ,True, $JobId)
If $errJobCreate = 0 Then
    MsgBox(0, '', "Job created successfully: Notepad.exe scheduled to run repeately at 14.30 (2:30 P.M.) PST on Mon, Wed, and Fri.")
Else
   MsgBox(0, '', "Job not created. Error code = " & $errJobCreate)
EndIf


Func __Generic_COM_Error()
    Local $hNumber = Hex($oComError_UDFGlobal.number, 8)
    
;blantly stolen from SvenP (We'll call it a 'port')
    MsgBox(0, 'XZip Com Error', 'There was COM Error!' & @CRLF & @CRLF & _
            'description is: ' & @TAB & $oComError_UDFGlobal.description & @CRLF & _
            'windescription:' & @TAB & $oComError_UDFGlobal.windescription & @CRLF & _
            'number is: ' & @TAB & $hNumber & @CRLF & _
            'lastdllerror is: ' & @TAB & $oComError_UDFGlobal.lastdllerror & @CRLF & _
            'scriptline is: ' & @TAB & $oComError_UDFGlobal.scriptline & @CRLF & _
            'source is: ' & @TAB & $oComError_UDFGlobal.source & @CRLF & _
            'helpfile is: ' & @TAB & $oComError_UDFGlobal.helpfile & @CRLF & _
            'helpcontext is: ' & @TAB & $oComError_UDFGlobal.helpcontext _
            )
    
    SetError(1)
EndFunc

From this example:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2") 
JobID = "Test"
Set objNewJob = objWMIService.Get("Win32_ScheduledJob")
errJobCreate = objNewJob.Create _
    ("Notepad.exe", "********143000.000000-420", _
        True , 1 OR 4 OR 16, ,True, JobId) 
If errJobCreate = 0 Then
    WScript.Echo "Job created successfully: " & VBNewLine _
        & "Notepad.exe scheduled to run repeately at 14.30 (2:30 P.M.) PST" & VBNewLine _
        & "on Mon, Wed, and Fri."
Else
    WScript.Echo "Job not created. Error code = " & errJobCreate
End If

Any tips?

TIA!

Edited by KXM

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

$objNewJob = $objWMIService.Get("Win32_ScheduledJob")

$errJobCreate = $objNewJob.Create ("C:\windows\Notepad.exe", "********143000.000000-420",

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

$objNewJob = $objWMIService.Get("Win32_ScheduledJob")

$errJobCreate = $objNewJob.Create ("C:\windows\Notepad.exe", "********143000.000000-420",

I am such a dumbass!!!

THNX!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0