Search code examples
batch-filemsgbox

Msgbox to prompt user if job (printing) is skip in batch


As suggested in my previous question, 1 question per thread. So Im here to open another question. Basically I want to prompt user that printing will be skip today because nothing to print, then the user will press OK, then code will continue to shutdown the computer. I want to do this to alert user that today's printing job have been run.

So I try some code like below, it seems working but i dont know how to implement in my main code.

@echo off
Call :Msgbox
if "%errorlevel%"=="1" GOTO SHUTDOWN
exit /b

:Msgbox
echo wscript.quit MsgBox ("Printing skipped.. Press ok to shutdow the computer", 48, "Shutdown Computer") >"%temp%\input.vbs"
wscript //nologo "%temp%\input.vbs"
exit /b
:SHUTDOWN

echo "%SystemRoot%\System32\shutdown.exe -s -t 60"

PAUSE

This is part of my main code where i want to place above code. https://stackoverflow.com/a/57609600/6409413

IF pdf file size greater than 9000byte > Print PDF for today > Then go to Shutdown

IF pdf file size less than 9000byte > Promp user using msgbox > user press OK > Skip Print PDF for today > Then go to Shutdown

Rem     ------------------------------------------------------------------------
Rem 4. Printing files with sizes over 9000 bytes

Set "_Exe1=%ProgramFiles(x86)%\Foxit Software\Foxit Reader\Foxit Reader.exe"

For %%A In ("%_Dir1%\c\%_FullDateString%.pdf")Do If %%~zA GTR 9000 (
    Echo Printing %%A&Echo=&"%_Exe1%" /t "%_Dir1%\c\%_FullDateString%.pdf")

UPDATE: Sort of working for now using code below. Any others way to achieve this?

Rem     ------------------------------------------------------------------------
Rem 4. Printing files with sizes over 9000 bytes

Set "_Exe1=%ProgramFiles(x86)%\Foxit Software\Foxit Reader\Foxit Reader.exe"
setlocal EnableDelayedExpansion
    For %%A In ("%_Dir1%\c\%_FullDateString%.pdf")Do ( set size=%%~zA 
        if !size! GTR 9000 (
            goto PRINT
        ) else if !size! LSS 9000 (
        goto NOPRINT

:NOPRINT
msg * /time:0 /w Printing skipped.. Press "OK" to shutdown the computer"

goto SHUTDOWN
                )
                )

:PRINT
Echo "Printing %%A&Echo=&"%_Exe1%" /t "%_Dir1%\c\%_FullDateString%.pdf")"

Rem     ------------------------------------------------------------------------
Rem 5. Shutting down computer
:SHUTDOWN
echo "%SystemRoot%\System32\shutdown.exe -s -t 60"

PAUSE

Solution

  • I really think that you're overcomplicating this unnecessarily. You're already using the shutdown command, which can pop up a dialog box to the end user.

    Rem     ------------------------------------------------------------------------
    Rem 4. Printing files with sizes over 9000 bytes
    
    Set "_Exe1=%ProgramFiles(x86)%\Foxit Software\Foxit Reader\Foxit Reader.exe"
    Set "_Msg=skipped"
    
    For %%A In ("%_Dir1%\c\%_FullDateString%.pdf")Do If %%~zA GTR 9000 (
        Set "_Msg=finished"&Echo Printing %%A&Echo=
        "%_Exe1%" /t "%_Dir1%\c\%_FullDateString%.pdf")
    
    Rem     ------------------------------------------------------------------------
    Rem 5. Shutting down computer
    
    ShutDown /S /T 60 /C "Printing %_Msg%, shutting down your computer." /D P:0:0
    

    Note: This section is a direct replacement for the previous code I provided, it is not based upon whatever you've posted above, (which is littered with issues).