Nelson Posted October 25, 2022 Posted October 25, 2022 I have a batch file that runs a backup of my system for off-site storage. The process works perfectly however to enhance the procedure would like a message box to show on-screen (Please wait) whilst the backup command itself runs. I have trawled through the net for ideas and found that Autoit may solve this problem, however I am totally lost with how to make it work. Below is the batch code I am using which is executed from a desktop icon run minimised. echo a = msgbox("SECURITY COPY OF E: DRIVE PROCEDURE" ^& vbCrLf ^& vbCrLf ^& " Please ensure USB stick is in place" ^& vbCrLf ^& "Please do not use computer while files copy" ^& vbCrLf ^& vbCrLf ^& " Do you wish to continue?",vbInformation + vbyesno,"Security copy") > "%temp%\popup.vbs echo WScript.Quit a >> "%temp%\popup.vbs" wscript.exe "%temp%\popup.vbs" set "exitcode=%errorlevel%" if errorlevel 7 goto no if errorlevel 6 goto check1 :no echo msgbox " Operation cancelled" ^& vbCrLf ^& vbCrLf ^& "Press OK to exit program",vbinformation,"Security copy" > "%temp%\popup.vbs" wscript.exe "%temp%\popup.vbs" goto end :check1 IF EXIST D:\ GOTO check2 GOTO noexist1 :noexist1 echo a = msgbox(" USB DRIVE IS NOT CONNECTED" ^& vbCrLf ^& vbCrLf ^& "PLEASE INSERT USB AND RETRY or CANCEL",vbCritical + vbRetryCancel,"Security copy") > "%temp%\popup.vbs echo WScript.Quit a >> "%temp%\popup.vbs" wscript.exe "%temp%\popup.vbs" set "exitcode=%errorlevel%" if errorlevel 4 goto check1 if errorlevel 2 goto no :check2 vol D: | find "Security" if not errorlevel 1 goto copy goto noexist2 :noexist2 removedrive D: -L echo a = msgbox(" INCORRECT USB DRIVE HAS BEEN MOUNTED" ^& vbCrLf ^& " VOLUME SECURITY EXPECTED" ^& vbCrLf ^& vbCrLf ^& "PLEASE INSERT CORRECT VOLUME AND RETRY or CANCEL",vbCritical + vbRetryCancel,"Security copy") > "%temp%\popup.vbs echo WScript.Quit a >> "%temp%\popup.vbs" wscript.exe "%temp%\popup.vbs" set "exitcode=%errorlevel%" if errorlevel 4 goto check2 if errorlevel 2 goto no :copy echo set WshShell = WScript.CreateObject("WScript.Shell") > %temp%\tmp.vbs echo WScript.Quit (WshShell.Popup( "DATA FROM E DRIVE NOW BEING COPIED",5 ,"Security copy", 0 + vbinformation + vbsystemmodal)) >> %temp%\tmp.vbs wscript /nologo %temp%\tmp.vbs robocopy e:\ d:\ /s /mir /log:"E:\My Documents\downloaded\programs\securitycopy.txt" /tee /np /XD $Recycle.bin /XD "System Volume Information" /XD "CDRIP" /XD "DVDTEMP" /XD "E:\My Documents\email" removedrive D: -L echo set WshShell = WScript.CreateObject("WScript.Shell") > %temp%\tmp.vbs echo WScript.Quit (WshShell.Popup( " SECURITY COPY OF E: DRIVE COMPLETED" ^& vbCrLf ^& " USB drive has been released"^& vbCrLf ^& vbCrLf ^& "Do you wish to read log before exiting program ?",30 ,"Security copy", 4 + vbInformation + vbSystemModal)) >> %temp%\tmp.vbs wscript /nologo %temp%\tmp.vbs set "exitcode=%errorlevel%" if errorlevel 7 goto end if errorlevel 6 goto log goto end :log start notepad "E:\My Documents\Downloaded\Programs\securitycopy.txt" goto end :end Basically a please wait message needs to be shown while the robocopy is executing, and if it can be done without resorting to Autoit then all the better !!! If not, well it is not a game changer. Many thanks.
andy_b Posted October 25, 2022 Posted October 25, 2022 Wouldn't it be easy to do it all within the cmd window and not run that minimised ?
Nelson Posted October 26, 2022 Author Posted October 26, 2022 As it stands, the procedure runs faultlessly with a user friendly interface and yes, it could all be run maximised. The question is merely if there was a way of coding a "please wait" message to stay on screen while the backup (2-3 mins duration) runs ... purely aesthetic. Thank you for your suggestion.
ThomL Posted October 26, 2022 Posted October 26, 2022 From a quick google there isn't a way to display the message the way you want - there will always be buttons I think it might be time to look at migrating this to a proper exe written in a different language. At the moment it's a hybrid of batch and vbs - I think you could make a hta (which is html + vbs) which may work. But I think it's probably a better approach to download Visual Studio community edition and then rebuild this tool in VB or similar. You already know what you want the tool to do and how you want it to look, it's just a case of googling how to achieve what the existing script is doing in VB piece by piece and build it up slowly, don't try to do everything at once. Making a Windows Forms based VB project in visual studio community you could then add controls like button and text etc. as required. You can enable/disable or display and hide these controls, or even make it look/act like a more traditional wizard. The please wait 'pop up' you can make a new form that has the text label control with the text "Please Wait" and then you show and hide the whole form as needed, disabling the original form that has all the options that the users chooses. I think migrating to a programming language rather than a scripting language will help and is the next step with your backup tool, doesn't have to be VB - I think VB might be one of the easier language to transition to from bat/vbs?
andy_b Posted October 26, 2022 Posted October 26, 2022 The problem is that spawning a message box using a "third party" be it Windows Script, Autoit or a custom message program, and keeping the message open while robocopy is working and then closing it when done from the current batch file. Could do it with taskkill but gets abit messy. As @ThomL said, might be better looking at another language.
Nelson Posted October 26, 2022 Author Posted October 26, 2022 Many thanks for the information. I must admt that I didn't think there was going to be a way of getting over this problem using the batch script, however your suggestion of Visual Studio Community sounds intriguing and would wile away the upcoming winter evenings. It will be good to get back to a bit of coding .... many years since RPG400 and before that Unique 3GL ... those were the days, dumb terminals and massive mainframes !!!! Thanks again and have a good day.
Nelson Posted October 26, 2022 Author Posted October 26, 2022 (edited) Quite so, as you will see I am going to have a look at Visual Studio ... Thank you for your assistance. I meant to add that the closest answer to this poser I found was to use start command to bring up a "wait" window just before the copy command then taskkill that process after the copy has completed. A rather tortuous way round but it actually works (apart of course for that pesky OK button). Procedure was to create a separate vbs for the wait window then a wscript call in an executable called Backupwait.exe can be used in the start command !!! code extract: :copy taskkill /im thunderbird.exe start "" "E:\My documents\downloaded\programs\backupwait.exe" robocopy "e:\my documents\email" d:\ /s /mir /log:"E:\My Documents\downloaded\programs\securityemail.txt" /tee /np removedrive D: -L taskkill /im wscript.exe I'm still going to revamp it all over time in Visual Studio, but for now the above will suffice.Thanks again for all your suggestions. Edited October 26, 2022 by Nelson Post script 1
andy_b Posted October 26, 2022 Posted October 26, 2022 (edited) If you wanted to use something like Autohotkey (https://www.autohotkey.com/) as an alternative, then something like this would do what you want and it would be fairly easy to replicate the rest of your script in a similar fashion: source := "C:\sourcefolder" destination := "C:\destinationfolder" Gui, +Toolwindow +Disabled Gui, Add, Text,, The script is working. Please be patient. Gui, Show,, Please Wait... RunWait, Robocopy %source% %destination% * /mov,,hide sleep 3000 # Just for testing to see message Gui, Destroy ExitApp Edited October 26, 2022 by andy_b
Nelson Posted October 27, 2022 Author Posted October 27, 2022 Many thanks for the suggestion. Another interesting scripting tool ...... must admit that I have never delved into this one. I'll see how I get on over the coming weeks with both Autohotkey and Visual Studio. Thankyou all.
HPlum78 Posted October 29, 2022 Posted October 29, 2022 Personally I would rewrite that in PowerShell and then use: Add-Type -assembly System.Windows.Forms I think that you would be able to do a write-progress to that form and have a progress bar displaying in a window. Would need to have ps in front of me to be sure and that's not now....
dmj Posted October 30, 2022 Posted October 30, 2022 The whole premise of users having to interact with a backup process is an anti-pattern. It should be completely automated and only notify when the process fails. There's no method for catching errors in the script either. Sorry to be so harsh but you really need to rethink this.
Nelson Posted October 30, 2022 Author Posted October 30, 2022 Many thanks for the info. There appear to a fair few ways around the "problem" which I will look into with interest. For now my start and taskill as explained in a previous answer, plus a disable then enable of mouse for good measure, is working reasonably well. Although not ideal and very messy. Thanks again.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now