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

    • hcI
      By hcI
      Hello I would like to know if there is a way to return a sentence in cmd when I launch from it (because I add arguments).
      For example, diskpart.exe which help to manage the key and hdd connected, when you launch it with the parameter "/f" the app return a sentence saying that it don't recognize the parameter "/f" and it return the sentence in the cmd where i started the application, not a new one.
      That's what I want to do but I couldn't find anything that would solve my problem on internet and on AutoIt like ConsoleWrite / ConsoleWriteError (don't work).
       
      Thanks
    • Duck
      By Duck
      I'm attempting to capture the output from the command line tool PSEXEC. I'm using AutoIT to run an instance of PSEXEC against a remote PC to audit Local Admins in my environment using net.exe (C:\Windows\System32> net localgroup administrators). However the usual trick I use to capture command line output does not appear to work well with PSEXEC, as the bottom portion of the output is missing from the return. Any ideas or recommendations are greatly appreciated.  
       
      Here is what I'm working with: 
      ;This script will read from a list of hosts and report who has local admin privileges on the machine #RequireAdmin Global $fileName = @ScriptDir & '\test.txt' ;hostlist, one host per line readHostList() ;Read list of hosts Func readHostList() Local $file = FileOpen($fileName, 0) While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop ConsoleWrite($line & @CRLF) ;MsgBox(0,0,$line) getLocalAdmins($line) WEnd FileClose($file) EndFunc ;run PSEXEC to list local admins Func getLocalAdmins($remotePC) Local $testFile = @ScriptDir &'\test234.txt' FileOpen($testFile, 1) Local $psexec = 'psexec \\' & $remotePC & ' net localgroup administrators' FileWriteLine($testFile, _RunCmd($psexec) ) FileClose($testFile) EndFunc ;Used to return CLI output Func _RunCmd($sCommand) Local $nPid = Run(@Comspec & " /c" & $sCommand, @SystemDir, @SW_Hide, 8), $sRet = "" If @Error then Return "ERROR:" & @ERROR ProcessWait($nPid) While 1 $sRet &= StdoutRead($nPID) If @error Or (Not ProcessExists ($nPid)) Then ExitLoop WEnd Return $sRet EndFunc  
      ## If i manually run the command on the remote PC via PSEXEC I will get the following output: 
      PsExec v2.11 - Execute processes remotely
      Copyright (C) 2001-2014 Mark Russinovich
      Sysinternals - www.sysinternals.com
      Starting net on PCNAME... on PCNAME...
      net exited on PCNAME with error code 0.
      -------------------------------------------------------------------------------
      admin
      Administrator
      Alias name     administrators
      Domain\Domain Admins
      Comment        Administrators have complete and unrestricted access to the computer/domain
      Members
      The command completed successfully.
       
      ## The returned output from running the above script is as follows:
      PsExec v2.11 - Execute processes remotely
      Copyright (C) 2001-2014 Mark Russinovich
      Sysinternals - www.sysinternals.com
      Alias name     administrators
      Connecting to PCNAME...
      Starting PSEXESVC service on PCNAME...
      Connecting with PsExec service on PCName...
      Starting net on PCNAME..
      net exited on PCNAME with error code 0.
       
      **Note to test this script PSEXEC must be in the system dir or the path in the script changed 
      PSEXEC tool: https://docs.microsoft.com/en-us/sysinternals/downloads/psexec
    • breakbadsp
      By breakbadsp
      I want to run a python script from autoit. 
      I know we can do this with shellexecute or run , but this python script takes 3 cmd line arguments.
      How to pass them from autoit script?
      I tried many ways.
      Following solution also not working 
      e.g. 
      RunWait( 'fullpath\Python.exe Scriptpath\ReadLog.py  -f "file.log" -k "key" -e "errMsg" ') Found solution:
      RunWait( 'fullpath\Python.exe ReadLog.py -f "file.log" -k "key" -e "errMsg" ', 'Working_directory_path')  
      PFB description:
      https://stackoverflow.com/questions/45757834/how-to-pass-command-line-arguments-to-a-python-script-anyscript-while-executin
       
    • Nareshm
      By Nareshm
      Hi All,
      I have excel file like this
      and i want to cut cell/text from excel to other software.

       
      I have to cut the cell of B column one by one and past into other software
      If Winexists("No Data Found")
      then restore cuted cell and goto next/down side cell
      How to do it ?
    • luckyluke
      By luckyluke
      Hello,
      Im trying to read the output from CMD using Dllcall, here is my code:
      #include <WinAPI.au3> #include <array.au3> Global Const $STD_OUTPUT_HANDLE = -11 Global Const $_CONSOLE_SCREEN_BUFFER_INFO = _ "struct;int dwSizeX;" & _ "short dwSizeY;" & _ "short dwCursorPositionX;" & _ "short dwCursorPositionY;" & _ "short wAttributes;" & _ "short Left;" & _ "short Top;" & _ "short Right;" & _ "short Bottom;" & _ "short dwMaximumWindowSizeX;" & _ "short dwMaximumWindowSizeY;endstruct" $pCmd = Run( "cmd.exe" ) Sleep(1000) $hCmd = WinGetHandle("") ConsoleWrite('handle:' & $hCmd & @CRLF) $aRet = DllCall("kernel32.dll", "int", "AttachConsole", "dword", $pCmd) ;_ArrayDisplay($aRet) If $aRet[0] <> 0 Then $vHandle_data='' $vHandle='' $vHandle_data = DllStructCreate($_CONSOLE_SCREEN_BUFFER_INFO) ; Screen Buffer structure $aRet1 = DllCall("kernel32.dll", "hwnd", "GetStdHandle", "dword", $STD_OUTPUT_HANDLE) if not @error Then $vHandle = $aRet1[0] $aRet = DllCall("kernel32.dll", "int", "GetConsoleScreenBufferInfo", "hwnd", $vHandle, _ "ptr", $vHandle_data) MsgBox(0, '1',DllStructGetData($vHandle_data, 'dwSizeX') & _WinAPI_GetLastErrorMessage()) EndIf It did not work, i got the message 'The handle is invalid'. Please help?
      Thank you in advance!