Jump to content

While Runwait


Recommended Posts

Hello,

I just wrote a script that should copy data into my cloud using xcopy (cmd), but I want the Status Bar I have in my GUI to change it's text like that:

working. -> working.. -> working... -> working. ...

I would also like to make a button which interrupts xcopy (simply closing it should do the trick), but I don't know how to call ProcessClose("xcopy.exe") using a button, while I'am waiting for RunWait to finish.

Example:

$command = 'xcopy "' & @DesktopDir & '\text.txt"' & ' "\\ADMIN-CLOUD\private\" /EECHIY'
$SW_STATE = @SW_HIDE
RunWait(@ComSpec & " /c " & '"' & $command & '"', @DesktopDir, $SW_State)

Please tell me if you need any further information! :)

Edited by WannaBeGut
Link to comment
Share on other sites

you could set a hotkey to terminate the process...

HotKeySet("ESC","_Terminate")

func _Terminate()

    if ProcessExists("process.exe") Then
        ProcessClose("process.exe")
    Else
        MsgBox("","error","process.exe doesn't exist")
        EndIf


    EndFunc

 

Link to comment
Share on other sites

1 hour ago, tonycst said:

u cant do while runwait.

runwait=pause the script until what ever runs exits.

u need to:

$process = run ("command")
while 1
    if $process = 0 then exitloop
wend

 

If I start cmd using Run it wont copy data, it will close instantly (the xcopy syntax is alright)

I need a verification that the script is still runnning and copying (in the program not the task manager or sth. like that)

Edited by WannaBeGut
Link to comment
Share on other sites

ya that does look a lil wicked , this is the best i can do for you, well for now anyway

#include <GUIConstantsEx.au3>
$command = 'xcopy "' & @DesktopDir & '\text.txt"' & ' "\\ADMIN-CLOUD\private\" /EECHIY'
$SW_STATE = @SW_HIDE
RunWait(@ComSpec & " /c " & '"' & $command & '"', @DesktopDir, $SW_State)
AdlibRegister("_CheckState",1000)


func _CheckState()
if ProcessExists("process.exe") Then
    _Working()
Else
    AdlibUnRegister("_CheckState")
EndIf
    EndFunc



func _Working()
    $hGui=GUICreate("Stuff is happening",100,100,0,0)
    $handle=WinGetHandle("Stuff is happening")
    GUISetState(@SW_SHOW,$handle)
    GUICtrlCreateLabel("working,..",0,50)
    $cancel=GUICtrlCreateButton("Cancel",0,75)

$process=ProcessExists("process.exe")
While $process<>0
    $process=ProcessExists("process.exe")
    if $process=0 Then
        ExitLoop
    EndIf

        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $cancel
                _Cancel()
                ExitLoop
        EndSwitch
    WEnd
EndFunc


Func _Cancel()

    MsgBox("","","you pressed cancel")

    if ProcessExists("process.exe") Then
        ProcessClose("process.exe")
    Else
        MsgBox("","error","process.exe doesn't exist")
        EndIf


    EndFunc

 

Edited by markyrocks
Link to comment
Share on other sites

#RequireAdmin
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>

#Region GUI START

$window_main = GUICreate("Backup", 418, 397, 340, 327)
$input_documents = GUICtrlCreateInput("", 104, 24, 241, 21)
$input_pictures = GUICtrlCreateInput("", 104, 56, 241, 21)
$input_videos = GUICtrlCreateInput("", 104, 88, 241, 21)
$input_music = GUICtrlCreateInput("", 104, 120, 241, 21)
$input_emails = GUICtrlCreateInput("", 104, 152, 241, 21)
$input_destination = GUICtrlCreateInput("", 104, 184, 241, 21)
$label_documents = GUICtrlCreateLabel("Documents:", 24, 24, 61, 17)
$label_pictures = GUICtrlCreateLabel("Pictures:", 24, 56, 45, 17)
$label_videos = GUICtrlCreateLabel("Videos:", 24, 88, 39, 17)
$label_music = GUICtrlCreateLabel("Music:", 24, 120, 35, 17)
$label_emails = GUICtrlCreateLabel("E-Mails:", 24, 152, 41, 17)
$label_destination = GUICtrlCreateLabel("Destination:", 24, 184, 60, 17)
$button_documents = GUICtrlCreateButton("...", 352, 24, 35, 23)
$button_pictures = GUICtrlCreateButton("...", 352, 56, 35, 25)
$button_videos = GUICtrlCreateButton("...", 352, 88, 35, 25)
$button_music = GUICtrlCreateButton("...", 352, 120, 35, 25)
$button_emails = GUICtrlCreateButton("...", 352, 152, 35, 25)
$button_destination = GUICtrlCreateButton("...", 352, 184, 35, 25)
$button_saveini = GUICtrlCreateButton("Save Settings to INI", 24, 336, 180, 25)
;$button_cancel = GUICtrlCreateButton("Cancel", 152, 336, 115, 25)
$button_start = GUICtrlCreateButton("Start", 215, 336, 180, 25)
$checkbox_documents = GUICtrlCreateCheckbox("Copy Documents", 40, 256, 97, 17)
$checkbox_pictures = GUICtrlCreateCheckbox("Copy Pictures", 144, 256, 81, 17)
$checkbox_videos = GUICtrlCreateCheckbox("Copy Videos", 240, 256, 81, 17)
$checkbox_music = GUICtrlCreateCheckbox("Copy Music", 40, 288, 73, 17)
$checkbox_emails = GUICtrlCreateCheckbox("Copy E-Mails", 144, 288, 81, 17)
$group_settings = GUICtrlCreateGroup("Turn on / off", 24, 224, 369, 97)
$checkbox_eabuffer = GUICtrlCreateCheckbox("Copy without E/A - Buffer", 240, 288, 145, 17)
$statusbar = _GUICtrlStatusBar_Create($window_main)
_GUICtrlStatusBar_SetText($statusbar, "Status: Waiting...")
GUISetState(@SW_SHOW)

#EndRegion GUI END

If FileExists(@ScriptDir & "\settings.ini") Then
    GUICtrlSetData($input_documents, IniRead(@ScriptDir & "\settings.ini", "Directories", "dir_documents", ""))
    GUICtrlSetData($input_pictures, IniRead(@ScriptDir & "\settings.ini", "Directories", "dir_pictures", ""))
    GUICtrlSetData($input_videos, IniRead(@ScriptDir & "\settings.ini", "Directories", "dir_videos", ""))
    GUICtrlSetData($input_music, IniRead(@ScriptDir & "\settings.ini", "Directories", "dir_music", ""))
    GUICtrlSetData($input_emails, IniRead(@ScriptDir & "\settings.ini", "Directories", "dir_emails", ""))
    GUICtrlSetData($input_destination, IniRead(@ScriptDir & "\settings.ini", "Directories", "dir_destination", ""))
EndIf

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $button_documents
            $dir_documents = FileSelectFolder("Select your documents folder...", "")
            GUICtrlSetData($input_documents, $dir_documents)
        Case $button_pictures
            $dir_pictures = FileSelectFolder("Select your pictures folder...", "")
            GUICtrlSetData($input_pictures, $dir_pictures)
        Case $button_videos
            $dir_videos = FileSelectFolder("Select your videos folder...", "")
            GUICtrlSetData($input_videos, $dir_videos)
        Case $button_music
            $dir_music = FileSelectFolder("Select your music folder...", "")
            GUICtrlSetData($input_music, $dir_music)
        Case $button_emails
            $dir_emails = FileSelectFolder("Select your e-mail folder...", "")
            GUICtrlSetData($input_emails, $dir_emails)
        Case $button_destination
            $dir_destination = FileSelectFolder("Select the folder your files should be saved in...", "")
            GUICtrlSetData($input_destination, $dir_destination)
        Case $button_saveini
            IniWrite(@ScriptDir & "\settings.ini", "Directories", "dir_documents", GUICtrlRead($input_documents))
            IniWrite(@ScriptDir & "\settings.ini", "Directories", "dir_pictures", GUICtrlRead($input_pictures))
            IniWrite(@ScriptDir & "\settings.ini", "Directories", "dir_videos", GUICtrlRead($input_videos))
            IniWrite(@ScriptDir & "\settings.ini", "Directories", "dir_music", GUICtrlRead($input_music))
            IniWrite(@ScriptDir & "\settings.ini", "Directories", "dir_emails", GUICtrlRead($input_emails))
            IniWrite(@ScriptDir & "\settings.ini", "Directories", "dir_destination", GUICtrlRead($input_destination))
        Case $button_start
            _backup(GUICtrlRead($input_documents), GUICtrlRead($input_pictures), GUICtrlRead($input_videos), GUICtrlRead($input_music), GUICtrlRead($input_emails), GUICtrlRead($input_destination), GUICtrlRead($checkbox_documents), GUICtrlRead($checkbox_pictures), GUICtrlRead($checkbox_videos), GUICtrlRead($checkbox_music), GUICtrlRead($checkbox_emails), GUICtrlRead($checkbox_eabuffer))
    EndSwitch
WEnd

Func _backup($documents, $pictures, $videos, $music, $emails, $destination, $cs_documents, $cs_pictures, $cs_videos, $cs_music, $cs_emails, $cs_eabuffer)

    $hTime = TimerInit()
    Local $aTimes

    _GUICtrlStatusBar_SetText($statusbar, "Status: Copying...")
    GUICtrlSetState($button_documents, 128)
    GUICtrlSetState($button_pictures, 128)
    GUICtrlSetState($button_videos, 128)
    GUICtrlSetState($button_music, 128)
    GUICtrlSetState($button_emails, 128)
    GUICtrlSetState($button_destination, 128)
    GUICtrlSetState($button_start, 128)
    GUICtrlSetState($button_saveini, 128)
    If Not FileExists($destination) Then DirCreate($destination)
    If $cs_eabuffer = 1 Then $options = "/ECHIY /J"
    If $cs_eabuffer = 4 Then $options = "/ECHIY"
    If $cs_documents = 1 Then
        _GUICtrlStatusBar_SetText($statusbar, "Status: Copying documents...")
        _cmd('xcopy "' & $documents & '" "' & $destination & '\Documents_' & @MDAY & '_' & @MON & '_' & @YEAR & '" '  & $options, 0)
    EndIf
    If $cs_pictures = 1 Then
        _GUICtrlStatusBar_SetText($statusbar, "Status: Copying pictures...")
        _cmd('xcopy "' & $pictures & '" "' & $destination & '\Pictures_' & @MDAY & '_' & @MON & '_' & @YEAR & '" '  & $options, 0)
    EndIf
    If $cs_videos = 1 Then
        _GUICtrlStatusBar_SetText($statusbar, "Status: Copying videos...")
        _cmd('xcopy "' & $videos & '" "' & $destination & '\Videos_' & @MDAY & '_' & @MON & '_' & @YEAR & '" '  & $options, 0)
    EndIf
    If $cs_music = 1 Then
        _GUICtrlStatusBar_SetText($statusbar, "Status: Copying music...")
        _cmd('xcopy "' & $music & '" "' & $destination & '\Music_' & @MDAY & '_' & @MON & '_' & @YEAR & '" '  & $options, 0)
    Endif
    If $cs_emails = 1 Then
        _GUICtrlStatusBar_SetText($statusbar, "Status: Copying emails...")
        _cmd('xcopy "' & $emails & '" "' & $destination & '\emails_' & @MDAY & '_' & @MON & '_' & @YEAR & '" '  & $options, 0)
    EndIf
    If @error = 0 Then
        MsgBox(0, "  Done...", " Finished copying data!")
        _GUICtrlStatusBar_SetText($statusbar, "Status: Success!")
    Else
        MsgBox(16, "  Error...", "An error occurred -> " & @error)
        _GUICtrlStatusBar_SetText($statusbar, "Status: Error: " & @error)
    EndIf
    GUICtrlSetState($button_documents, 64)
    GUICtrlSetState($button_pictures, 64)
    GUICtrlSetState($button_videos, 64)
    GUICtrlSetState($button_music, 64)
    GUICtrlSetState($button_emails, 64)
    GUICtrlSetState($button_destination, 64)
    GUICtrlSetState($button_start, 64)
    GUICtrlSetState($button_saveini, 64)
EndFunc

Func _cmd($command, $SW_State_Input)
    If $SW_State_Input = 0 Then $SW_State = @SW_HIDE
    If $SW_State_Input = 1 Then $SW_State = @SW_SHOW
    If $SW_State_Input = 2 Then $SW_State = @SW_MAXIMIZE
    If $SW_State_Input = 3 Then $SW_State = @SW_MINIMIZE
    If $SW_State_Input = 4 Then $SW_State = @SW_SHOWDEFAULT
    If $SW_State_Input = 5 Then $SW_State = @SW_SHOWMAXIMIZED
    If $SW_State_Input = 6 Then $SW_State = @SW_SHOWMINIMIZED
    If $SW_State_Input = 7 Then $SW_State = @SW_SHOWMINNOACTIVE
    $CMD = RunWait(@ComSpec & " /c " & '"' & $command & '"', @DesktopDir, $SW_State)
        If @Error = 0 Then
            Return $CMD
        Else
            Return @Error
        EndIf
EndFunc

That'st the full script.

Edited by WannaBeGut
Link to comment
Share on other sites

#include <GUIConstantsEx.au3>
$command = 'xcopy "' & @DesktopDir & '\text.txt"' & ' "\\ADMIN-CLOUD\private\" /EECHIY'
$SW_STATE = @SW_HIDE

$hGui = GUICreate("Stuff is happening", 100, 100, 0, 0)
$handle = WinGetHandle("Stuff is happening")
GUISetState(@SW_SHOW, $handle)
GUICtrlCreateLabel("working,..", 0, 50)
$cancel = GUICtrlCreateButton("Cancel", 0, 75)
Global $i_PID = Run(@ComSpec & " /c " & $command , @DesktopDir, $SW_STATE) ; careful here, all those """"""
Global $SEC = @SEC
While 1
    If $SEC <> @SEC Then ; to ease up on the CPU, check every sec.
        $SEC = @SEC
        If Not ProcessExists($i_PID) Then ExitLoop
    EndIf

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $cancel; ,$GUI_EVENT_CLOSE <--- should go here ?
            Do
                ProcessClose($i_PID)
                Sleep(200)
            Until Not ProcessExists($i_PID)
            ExitLoop
    EndSwitch
WEnd

That criteria should be functional.

Edited by argumentum
tweak the code

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

i edited my last post bc i think the op's issue is stuff happening during the runwait.  I think the only way to make that happen is to use adlibregister?

 

 

edit.  i edited again to fix a typo but ya im just posting examples not meant the be all end all.  im just board,  don't have a program in the works so i just trying to help someone if i can.   plus its good exercise

Edited by markyrocks
Link to comment
Share on other sites

6 minutes ago, WannaBeGut said:

I really appreciate it ! :D

no sweat.  Upon further review, I would adlibunregister the checkstate function after the working function starts but dammit now that im thinking about this the program could possibly pause forever in my above scenario......

Edited by markyrocks
Link to comment
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
 Share

×
×
  • Create New...