Jump to content
Sign in to follow this  
gte

Trying to use the runwait command with a scheduled task

Recommended Posts

gte

Does anyone have any idea what I've coded wrong?

The box at the bottom is just for me trying to troubleshoot and see the output???

Here is the gui (very very simple)

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>



$Form3 = GUICreate("Test Scheduled Task Creation", 370, 291, 1677, 414)
$schtaskcreatebutton = GUICtrlCreateButton("Create Task", 144, 64, 91, 73, 0)
$cmdfiletext = GUICtrlCreateEdit('', 16, 184, 337, 41, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN))

GUICtrlSetData(1, $cmdfiletext)
GUISetState(@SW_SHOW)

GUICtrlSetOnEvent($schtaskcreatebutton, "createtask")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd





func createtask()
        
        
        $server = 'server'
        $schtaskusername = 'admin'
        $schtaskpassword = 'p@ssw1rd'
        $schtaskfrequency = 'once'
        $schtaskname = 'Update'
        $schtaskrunfile = 'd:\temp\updatetask.exe'
        $schtaskstartime = '08:10:00'
        $schtaskstartdate = '01/01/2010'

;$schtaskcreate = RunWait('cmd.exe', '%systemroot%\system32\', 'schtasks /create /s ' & '\\' & $server & ' /u ' & $schtaskusername &  ' /p ' & $schtaskpassword & ' /ru ' & $schtaskusername & ' /rp ' & $schtaskpassword & ' /sc ' & $schtaskfrequency & ' /tn ' & $schtaskname & ' /tr ' & $schtaskrunfile & ' /ST ' & $schtaskstartime & ' /SD ' & $schtaskstartdate) 
    
        
EndFunc

Share this post


Link to post
Share on other sites
Valuater

You can not have GUIGetMsg() working with OnEvent-Mode... GUICtrlSetOnEvent()

You will need to go one direction or the other, not both

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
Valuater

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form3 = GUICreate("Test Scheduled Task Creation", 370, 291);, 1677, 414)
$schtaskcreatebutton = GUICtrlCreateButton("Create Task", 144, 64, 91, 73, 0)
$cmdfiletext_Edit = GUICtrlCreateEdit('', 16, 184, 337, 41, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_WANTRETURN))
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $schtaskcreatebutton
            createtask()

    EndSwitch
WEnd

Func createtask()
    MsgBox(4096, "Test", "test OK    ", 5)
    Return

    $server = 'server'
    $schtaskusername = 'admin'
    $schtaskpassword = 'p@ssw1rd'
    $schtaskfrequency = 'once'
    $schtaskname = 'Update'
    $schtaskrunfile = 'd:\temp\updatetask.exe'
    $schtaskstartime = '08:10:00'
    $schtaskstartdate = '01/01/2010'

    ;$schtaskcreate = RunWait('cmd.exe', '%systemroot%\system32\', 'schtasks /create /s ' & '\\' & $server & ' /u ' & $schtaskusername &  ' /p ' & $schtaskpassword & ' /ru ' & $schtaskusername & ' /rp ' & $schtaskpassword & ' /sc ' & $schtaskfrequency & ' /tn ' & $schtaskname & ' /tr ' & $schtaskrunfile & ' /ST ' & $schtaskstartime & ' /SD ' & $schtaskstartdate)

EndFunc   ;==>createtask

there were a couple of errors too!

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
gte

For anyone that just wants to test it outside of the GUI, here is what I finally got to work

Put your own values in of course

$server = 'servername'
        $schtaskusername = 'domain\user'
        $schtaskpassword = 'password'
        $schtaskfrequency = 'once'
        $schtaskname = '"Library list update"'; MAKE SURE THIS POS HAS QUOTES OR A SINGLE WORD NAME!!! I WASTED 2 HOURS BECAUSE OF THIS
        $schtaskrunfile = 'd:\temp\updatetask.exe'
        $schtaskstartime = '08:10:00'
        $schtaskstartdate = '01/01/2010'

$val1 = RunWait('schtasks.exe /create /s ' & '\\' & $server & ' /u ' & $schtaskusername &  ' /p ' & $schtaskpassword & ' /ru ' & $schtaskusername & ' /rp ' & $schtaskpassword & ' /sc ' & $schtaskfrequency & ' /tn ' & $schtaskname & ' /tr ' & $schtaskrunfile & ' /ST ' & $schtaskstartime & ' /SD ' & $schtaskstartdate, @WindowsDir)

Share this post


Link to post
Share on other sites
gte

Thanks!

Here is what I got to work

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $cmdfiletext = ''

$Form3 = GUICreate("Test Scheduled Task Creation", 370, 291, 1677, 414)
$schtaskcreatebutton = GUICtrlCreateButton("Create Task", 144, 64, 91, 73, 0)
$cmdfiletext = GUICtrlCreateEdit('', 16, 184, 337, 41, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN))

GUICtrlSetData(1, $cmdfiletext)
GUISetState(@SW_SHOW)

GUICtrlSetOnEvent($schtaskcreatebutton, "createtask")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $schtaskcreatebutton
            createtask()

    EndSwitch
WEnd





func createtask()
        
    $server = 'servername'
        $schtaskusername = 'domain\user'
        $schtaskpassword = 'password'
        $schtaskfrequency = 'once'
        $schtaskname = '"Library list update"'; MAKE SURE THIS POS HAS QUOTES OR A SINGLE WORD NAME!!! I WASTED 2 HOURS BECAUSE OF THIS
        $schtaskrunfile = 'd:\temp\updatetask.exe'
        $schtaskstartime = '08:10:00'
        $schtaskstartdate = '01/01/2010'

$val1 = RunWait('schtasks.exe /create /s ' & '\\' & $server & ' /u ' & $schtaskusername &  ' /p ' & $schtaskpassword & ' /ru ' & $schtaskusername & ' /rp ' & $schtaskpassword & ' /sc ' & $schtaskfrequency & ' /tn ' & $schtaskname & ' /tr ' & $schtaskrunfile & ' /ST ' & $schtaskstartime & ' /SD ' & $schtaskstartdate, @WindowsDir)


        
EndFunc

----------------------------------

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form3 = GUICreate("Test Scheduled Task Creation", 370, 291);, 1677, 414)
$schtaskcreatebutton = GUICtrlCreateButton("Create Task", 144, 64, 91, 73, 0)
$cmdfiletext_Edit = GUICtrlCreateEdit('', 16, 184, 337, 41, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_WANTRETURN))
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $schtaskcreatebutton
            createtask()

    EndSwitch
WEnd

Func createtask()
    MsgBox(4096, "Test", "test OK    ", 5)
    Return

    $server = 'server'
    $schtaskusername = 'admin'
    $schtaskpassword = 'p@ssw1rd'
    $schtaskfrequency = 'once'
    $schtaskname = 'Update'
    $schtaskrunfile = 'd:\temp\updatetask.exe'
    $schtaskstartime = '08:10:00'
    $schtaskstartdate = '01/01/2010'

    ;$schtaskcreate = RunWait('cmd.exe', '%systemroot%\system32\', 'schtasks /create /s ' & '\\' & $server & ' /u ' & $schtaskusername &  ' /p ' & $schtaskpassword & ' /ru ' & $schtaskusername & ' /rp ' & $schtaskpassword & ' /sc ' & $schtaskfrequency & ' /tn ' & $schtaskname & ' /tr ' & $schtaskrunfile & ' /ST ' & $schtaskstartime & ' /SD ' & $schtaskstartdate)

EndFunc   ;==>createtask

there were a couple of errors too!

8)

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  

×