open a file and wait for it to quit/exit then continue batch file
SETLOCAL enableextensions enabledelayedexpansion
:: change your Given/First name
set MYSELF=Feli开发者_运维百科pe
set BOSS=Jon
set "MYFILE=Timesheet_%MYSELF%_FY10.11_Version_1.1.xls"
set "MYLOCKEDFILE=%MYFILE%.gpg"
set "SAFETY=~%MYFILE%"
:: PFx86: this variable is needed to avoid breaking 'if' statement below
set "PFx86=%PROGRAMFILES(x86)%"
if exist (%PFx86%) (
set "GPGBIN=%PFx86%\GNU\GnuPG\"
echo 64-bit windows...
) else (
set "GPGBIN=%PROGRAMFILES%\GNU\GnuPG\"
echo 32-bit windows...
)
if exist %MYLOCKEDFILE% (
echo locked file found
for %%F in (%MYLOCKEDFILE%) do (
set ATTRIBS=%%~aF
set READ_ATTRIB=!ATTRIBS:~1,1!
if !READ_ATTRIB!==r (
echo locked file is RO...
:: svn lock
TortoiseProc.exe /command:lock /path:%MYLOCKEDFILE%
) else (
echo locked file is RW...
)
:: decrypt
echo decrypting...
"%GPGBIN%\gpg.exe" "%MYLOCKEDFILE%"
)
if exist %MYFILE% (
echo opening %MYFILE%...
%MYFILE%
echo encrypting...
:: encrypt
gpg.exe -r %BOSS% -r %MYSELF% -e %MYFILE%
echo deleting %MYFILE%...
del %MYFILE%
)
)
I have a batch file that does the following
- decrypts a timesheet.xls.gpg file
opens it with
"timesheet.xls"
then encrypts it again with gpg
When the timesheet gets opened, it immediately continues to the 'encrypt' phase.
How can I make it wait until the XLS file is closed to resume the running of the script (without explicit user intervention)?
I used
START /WAIT "title" "..\path\to\excel.exe" "%MYFILE%"
And it worked.
You might be better off forgetting about using a batch file for this and instead use AutoIt, which can wait until the opening of the spreadsheet is finished by Excel and then continue on from there to the encryption phase.
To quote from their page:
AutoIt v3 is a freeware BASIC-like scripting language designed for automating the Windows GUI and general scripting. It uses a combination of simulated keystrokes, mouse movement and window/control manipulation in order to automate tasks in a way not possible or reliable with other languages (e.g. VBScript and SendKeys). AutoIt is also very small, self-contained and will run on all versions of Windows out-of-the-box with no annoying “runtimes” required!
This will be a better fit for the task at hand.
精彩评论