What's shutting down my batch files?


  1. Posts : 118
    Windows 7 and 10
       #1

    What's shutting down my batch files?


    I'm using Win10 22H2. I have several batch files running. Each is waiting for me at a Pause command. I work on something else for a while. When I return, I find that the batch files are gone - I mean, the running sessions have been shut down. This has happened repeatedly within the past few days; it did not happen previously. What is the best way to find what is closing those batch files? (Or if you already have an idea of what the cause might be, that could help me cut to the chase.)
      My Computer


  2. Posts : 18,032
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
       #2

    Hello @raywood,

    raywood said:
    I have several batch files running. Each is waiting for me at a Pause command.
    Is it just the pause command, or is it for example something like echo ^>Press ANY key to EXIT . . . & pause >nul & Exit ?

    It could be at the time of closure, that the command window was Active, and when you pressed a key, that triggered the closure of the Batch file. It is the focus of the Keyboard that could be the cause !
      My Computer


  3. Posts : 17,103
    Windows 10 Home x64 Version 22H2 Build 19045.5371
       #3

    Please post the response to this command
    Code:
    PowerCfg -a
    If you have S0 Modern standby then it would seem to be responsible if your display has been allowed to go off [by its Power Options setting] at any time before you return to look at those batch files.
    I disabled S0 Modern standby ages ago. I don't recall it actually closing batch files [I thought it merely stopped them progressing].


    All the best,
    Denis
      My Computer


  4. Posts : 118
    Windows 7 and 10
    Thread Starter
       #4

    Thanks, but I think that's not it. Here's what powercfg -a gives me:

    Code:
    The following sleep states are available on this system:
        Standby (S3)
        Hibernate
        Hybrid Sleep
    
    The following sleep states are not available on this system:
        Standby (S1)
            The system firmware does not support this standby state.
    
        Standby (S2)
            The system firmware does not support this standby state.
    
        Standby (S0 Low Power Idle)
            The system firmware does not support this standby state.
    
        Fast Startup
            This action is disabled in the current system policy.
      My Computer


  5. Posts : 17,103
    Windows 10 Home x64 Version 22H2 Build 19045.5371
       #5

    In that case, you are not being affected by S0 Modern standby so you can ignore everything I wrote.

    Before turning away to work on something else, I suggest you look in the batch files' windows to check that they have reached the Pause commands that you expect.
    I wonder if, instead of reaching your Pause commands, they are crashing.

    Denis
      My Computer


  6. Posts : 118
    Windows 7 and 10
    Thread Starter
       #6

    Denis, thanks for trying. Yeah, I have definitely been leaving them at Pause.

    So there is no log or other record of what has been happening? I had the impression that Windows logs everything. I just don't know what log would cover something like this. But maybe there isn't one.

    Whatever it is, it is closing them all, not just one. Three or four batch files at the same time.
      My Computer


  7. Posts : 17,103
    Windows 10 Home x64 Version 22H2 Build 19045.5371
       #7

    Windows logs many things but there is, from the user's perspective, little logic in what's covered. It might be, but this is only speculation, that Windows records things that its own processes need to refer to to do their jobs - so a network connection to the internet is recorded so that other Windows components can use that to decide whether to get out of bed or not.

    Many PowerShell events are recorded.
    I've never looked for or stumbled across any records of batch file execution.

    This is just an idea:
    1 Set up your Taskbar clock to show seconds - Hide or Show Seconds on Taskbar Clock - TenForumsTutorials
    2 Set up your phone to start videoing your display - make sure it captures the Taskbar & the clock display.
    3 Go about your normal activities including starting the batch files.
    4 Turn away to do something else.
    5 When you find that the batch files icons have disappeared, play back the video to get the time of disappearance.
    6 Open Event viewer, Custom views, Administrative events [which is a poncy way of saying, All events] and look for records at the time the icons disappeared.
    7 If you see anything that seems worthwhile, note [from the lower part of the window] its Log name, Source & EventID.
    What's shutting down my batch files?-unexpected-shutdown-event-log-name-source-eventid.png
    8 Come back and discuss what you've found. It will be pot luck if I or another contributor have any useful observations to make about what you've discovered. Event viewer interpretation skills generally depend on having torn your hair out investigating specific problems before.


    Best of luck,
    Denis
      My Computer


  8. Posts : 1,088
    Windows 7
       #8

    There's two possible explanations:
    1. Windows is abruptly terminating your CMD sessions.
    2. CMD is proceeding to the next command, after PAUSE.

    To settle this question, add some logging after the PAUSE to trace if it made it past this moment without your knowledge. If there's no logged message, then you know it was killed.

    Code:
    pause
    
    setlocal
    for /f "tokens=*" %%F in ('date /t') do (set DATE=%%F)
    for /f "tokens=*" %%F in ('time /t') do (set TIME=%%F)
    
    echo %DATE% %TIME% %0 >> C:\Users\GARLIN\Documents\log.txt
    endlocal
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 08:27.
Find Us




Windows 10 Forums