I'm working in Windows 10 Professional.
I have a batch file (code below) that checks whether files on the local machine are older than some files on a file server and updates them if necessary by pulling down a zip file and expanding it.
There are four states the user can end up in: • There are no files on the server to deploy locally • There is no zip file on the server to copy • The local files are already current • The local files need to be updated
For each of these states, I'd like a message box telling the user what state they're in, especially because the file copy can take ten minutes.
All of this works perfectly if I execute the batch file from the command line. However if I double-click the batch file from File Explorer, the message boxes are children of the batch process and are killed as soon as the batch script ends — which is often immediately after the message box is invoked. (At the end of the file copy, I'd like to notify the user that the files are in place.)
The batch script below uses msg to try to invoke the message box, and (as mentioned) that works perfectly well if I invoke the script from a command line but fails if I invoke the script from File Explorer. I've also tried creating a vbscript message box and invoking that with either start /WAIT or call, and I've tried mshta javascripting, msg, and pretty much anything else I could find, (the options detailed in Show a popup/message box from a Windows batch file) but the message box always disappears as soon as the script ends, which is immediately.
How can I invoke a message box that is not going to disappear immediately when the script has been invoked from File Explorer?
Thanks!
@echo off
set never=Never
set null=0
:: First, see if there is an environment available online.
IF EXIST "\\FileServer\Client\Application\JRE\release" (
:: The environment exists. When was it deployed?
FOR %%A IN ("\\FileServer\Client\Application\JRE\release") do (
SET tempDateTimeS=%%~tA
set lastServerUpdate=%tempDateTimeS:~0,10%.%tempDateTimeS:~11,5%
)
) ELSE (
set lastServerUpdate=%never%
)
:: Next, see if there is a local environment in place.
IF EXIST "C:\SL\Application\JRE\release" (
:: The environment exists. when was it deployed on the server?
FOR %%B IN (C:\SL\Application\JRE\release) DO (
set tempDateTimeL=%%~tB
set lastLocalUpdate=%tempDateTimeL:~0,10%.%tempDateTimeL:~11,5%
)
) ELSE (
set lastLocalUpdate=%never%
)
:: Finally, see when the last zip file was made on the server.
IF EXIST "\\FileServer\Client\Application.zip" (
:: Get the update date of the zip file. Is it newer than the deployment?
FOR %%C IN ("\\FileServer\Client\Application.zip") DO (
set tempDateTimeZ=%%~tC
set zipUpdateTime=%tempDateTimeZ:~0,10%.%tempDateTimeZ:~11,5%
)
) ELSE (
set zipUpdateTime=%null%
)
IF %lastServerUpdate% == %never% (
:: There is no code deployed on the server
msg * There is no deployment available on the server.
) ELSE IF %lastServerUpdate% GTR %zipUpdateTime% (
:: The zip file on the file server needs to be rebuilt.
msg * Create a new ZIP file on the server and rerun this batch file.
) ELSE IF %lastServerUpdate% == %lastLocalUpdate% (
:: The local version matches the newest available on the server.
msg * The local environment is already current.
) ELSE (
msg * Starting local deployment.
:: Get the zip file from the server.
xcopy "\\FileServer\Client\Application.zip" "C:\SL" /Y
:: Unzip it locally.
"C:\Program Files\7-Zip\7z" x application.zip -o"C:\SL" -aoa
:: Rename the downloaded zip file to keep it available for future restoration
ren "C:\SL\Application.zip" "%date%-Application.zip"
msg * The local environment is ready.
)