Sign in to follow this  
Followers 0
gcue

script does not exit consistently

4 posts in this topic

#1 ·  Posted (edited)

hello all.

i have a script that doesn't seem to exit consistently. i figure it's probably because of runwait

i am using schtasks to run a process on a remote PC. sometimes the pc can be in another country so i want to make sure the creation of the task gets created before i try to run it. also i want to make sure that the task runs before i check the registry results it creates.

i thought about putting in a sleep after task creation and after task run but i feel thats unecessary waiting time if the pc is local. and if the pc is in another country and on a dsl connection who knows what a proper sleep would wait..... that's why i went with runwait =)

Check_Encryption()

Func Check_Encryption()

        $asset = "d0105465"
        $task = "cmd /c sgestate /R /L /E"
        $task_name = "Encryption"
        _RemoteRun($asset, $task_name, $task)

        $status = "UNABLE_TO_ATTAIN"

        $return_code = RegRead("\\" & $asset & "\HKLM\Software\Utimaco\SGEasy", "System Status")

        If $return_code = "42" Then
            $status = "ENCRYPTED"
        EndIf

        If $return_code = "43" Then
            $status = "ENCRYPTING"
        EndIf

        MsgBox(0, "", $asset & ": " & $status)

EndFunc

Func _RemoteRun($asset, $task_name, $task)

    RunWait("SCHTASKS /CREATE /S \\" & $asset & " /RU SYSTEM /TN """ & $task_name & """ /TR """ & $task & """ /SC ONCE /ST 00:00:00", "", @SW_HIDE)
    RunWait('SCHTASKS /RUN /S \\' & $asset & ' /TN ""' & $task_name & '""', "", @SW_HIDE)
    Run('SCHTASKS /DELETE /S \\' & $asset & ' /TN ""' & $task_name & '""', "", @SW_HIDE)

EndFunc   ;==>_RemoteRun
Edited by gcue

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Perhaps checking the return value of runwait may help.

Func _RemoteRun($asset, $task_name, $task)
    $_CREATE = RunWait("SCHTASKS /CREATE /S \\" & $asset & " /RU SYSTEM /TN """ & $task_name & """ /TR """ & $task & """ /SC ONCE /ST 00:00:00", "", @SW_HIDE)
    If $_CREATE > 0 Then
        $_RUN = RunWait('SCHTASKS /RUN /S \\' & $asset & ' /TN ""' & $task_name & '""', "", @SW_HIDE)
        If $_RUN > 0 Then
            Run('SCHTASKS /DELETE /S \\' & $asset & ' /TN ""' & $task_name & '""', "", @SW_HIDE)
        EndIf
    EndIf
EndFunc
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

brilliant!

thank you very much

Share this post


Link to post
Share on other sites

added this to help determine if it was run or not then rerun if not:

Func Dashboard_RemoteRun($asset, $task_name, $task)

    $task_run = False

    $create = RunWait("SCHTASKS /CREATE /S \\" & $asset & " /RU SYSTEM /TN """ & $task_name & """ /TR """ & $task & """ /SC ONCE /ST 00:00:00", "", @SW_HIDE)
    If $create > 0 Then
        $run = RunWait('SCHTASKS /RUN /S \\' & $asset & ' /TN ""' & $task_name & '""', "", @SW_HIDE)
        If $run > 0 Then
            $task_run = True
            Run('SCHTASKS /DELETE /S \\' & $asset & ' /TN ""' & $task_name & '""', "", @SW_HIDE)
        EndIf
    EndIf
    
    Return $task_run

EndFunc   ;==>Dashboard_RemoteRun

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