WannaBeGut

While Runwait

15 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

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

 

1 person likes this

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

Show me yours ( the working script )
and I'll show you mine ( fixed script ).

2 hours ago, WannaBeGut said:

...but I want the Status Bar I have in my GUI to change...

so .... where is it ?

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

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
1 person likes this

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

#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

Share this post


Link to post
Share on other sites
1 minute ago, WannaBeGut said:

That'st he full script.

That's too much, I'll show you based on the prior script, ...in a few minutes 

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

#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
1 person likes this

Share this post


Link to post
Share on other sites
6 minutes ago, argumentum said:

That's too much, I'll show you based on the prior script, ...in a few minutes 

It works, thanks alot ! :-)

1 person likes this

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites
22 minutes ago, markyrocks said:

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?

I really appreciate it ! :D

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

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

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

  • Similar Content

    • vyperhand
      By vyperhand
      I'm struggling to launch a VBS file via autoit using RunWait.  Due to the nature of the deployment tool I am using for said script, I only know that the .vbs files will be in the same directory as my AutoIt-generated .exe, but not what that path will be.  The path will look something like this:
      c:\programdata\vendor\lots\of\folders\randomnumber
      This is generated during deployment and I have no way of predicting the path - therefore, I am not sure how to call back to "same directory" in order to successfully launch the .vbs.
      This line is as close as I have gotten - this fires off the cmd window, but it closes immediately with out information, and the .vbs is not launched.
      RunWait (@ComSpec & " /c" & 'cscript.exe WORKPLEASE.vbs ALL /Q /NoCancel') I thought /c might be the problem, but leaving out the /c element causes me not to even see the momentary CMD window flash by.  Any help will be greatly appreciated, and thanks in advance.
    • lewisg
      By lewisg
      Suddenly a RunWait command has stop working after 2 years of no errors, issues, or problems. The code uses RunWait to start Plink.exe, a command-line remote connection tool similar to UNIX ssh. I'm using it to ssh to a linux (Centos) machine, run a Perl script, and redirect the output to a file on a PC running the AutoIt script.  
       
      $FilePath = "C:\AutoIT\LED" $FilePathPlus = $FilePath & "\plink.exe" $Code1 = RunWait(@ComSpec & " /c " & $FilePathPlus & " -ssh -l root -pw ?????? 10.170.4.163 /usr/local/nagios/etc/led.pl > C:\AutoIT\LED\led.txt ", @SW_SHOW) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : @ComSpec & " /c " & $FilePathPlus & " -ssh -l root -pw ????? 10.170.4.163 /usr/local/nagios/etc/led.pl > C:\AutoIT\LED\led.txt " = ' & @ComSpec & " /c " & $FilePathPlus & " -ssh -l root -pw ?????? 10.170.4.163 /usr/local/nagios/etc/led.pl > C:\AutoIT\LED\led.txt " & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console The ConsoleWrite output when cut-n-pasted into a DOS box produces the expected file so I know it works. I've also tried many variations of the function moving, adding, and changing the " and ' (quote) marks. Also tried it without the @ComSpec macro and other related functions...e.g.  ShellExecuteWait , etc.
      The PC is a Windows 10 64bit and AutoIT is version 3.3.14.2.
      Searching here and Google has not yielded any clues that helped. 
    • Simpel
      By Simpel
      Hi.
      Thanks to this post (https://www.autoitscript.com/forum/topic/189553-writing-to-cmd/?do=findComment&comment=1361142) I can now write a helpfile to the cmd when for instance passing parameter -h or -help at cmd. But then cmd is blocked by the script (I had to free it with CTRL+BREAK):
      #include <WinAPI.au3> _WinAPI_AttachConsole() $hConsole = _WinAPI_GetStdHandle(1) _WinAPI_WriteConsole($hConsole, "Print helpfile................" & @CRLF) Inside MSDN Library then I found this sentence: A process can use the FreeConsole function to detach itself from its console.
      But I don't find something like _WinAPI_FreeConsole(). How can I do it in another way?
      Regards, Conrad
    • TheAutomator
      By TheAutomator
      A fullscreen console with custom commands!

      Introduction:
      Hi everyone!
      This funny project started as a question in the help section:
      https://www.autoitscript.com/forum/topic/174404-edit-detect-key-before-updating-content/
      I'd like to share this script with everyone that is interested. 
       
      Why would I want it?
      You like the old style fullscreen console (like in the old day's), You can add custom commands, You can customize the font a lot more compared to cmd.exe, You can share ideas or add tweaks to the script.  
      Still to do:
      Write a simple custom programming language to implement this tool. Writing a little help file / pdf to describe my little programming language. Add little sound effects like a beep if there is a syntax error (optional). Clean up and modify Console.Au3 content. Add an option to have to type a login password (optional). Make an optional installer that also gives scripts for this tool a custom icon and open with command. ...Call Neo?  
      Thanks to:
      xxaviarxx: debugging, some ideas. jguinch: debugging, adding a bunch of tweaks and ideas. kylomas: debugging, new ideas.  
      Edits and updates:
      Added usage of tab key in edit control Edit has focus now on startup I'm currently rewriting a simple custom programming language to implement this tool.  
      UDF download: Console.au3
       
      Regards
      TheAutomator
    • goodmanjl531
      By goodmanjl531
      Hope someone can help as quotes within quotes is always confusing.  I am creating a silent install of printer software and want to call via runwait comspec line.
      The call within a cmd line is below
      samsung.exe /s /n"Samsung SL-M3220ND" /p"xxx"
      xxx will be stored as a variable  $PrinterIP which would be as example  10.10.10.20    I need to use a variable as i am doign this for a business and need it to be based on the store i install at that has a specific IP range.
       
      I started with the below as 2 possibilities but no luck..
      RunWait(@ComSpec & "/c " & "samsung.exe /s /n""Samsung SL-M3220ND"" /p""" & $PrinterIP ") RunWait(@ComSpec & "/c " & "samsung.exe /s /n'Samsung SL-M3220ND' /p'" & $PrinterIP '") but i cant get it to compile as i have errors on the line..  thanks in advance.