FirstLogonCommands with shutdown in the sequence


  1. Posts : 37
    Windows
       #1

    FirstLogonCommands with shutdown in the sequence


    I've been experimenting, to try to determine the behavior of synchronous commands with the FirstLogonCommands in OOBE. My initial question was:

    If a 'shutdown /r /t 0' falls somewhere in the middle of the command sequence, will the remaining commands be executed when the system comes back up and Administrator is logged back in?
    As far as I can tell, the way it actually works is that the shutdown is simply held off until all the remaining synchronous commands (perhaps until all remaining OOBE activities) are completed.

    This is kind of nice, because if you know that you want your FirstLogonCommands to end with a restart, you can add the shutdown as the first command and then start adding more commands as you think of them. That way you don't need to keep re-assigning the order numbers to keep pushing shutdown to the back.

    Has anybody seen any documentation from Microsoft explicitly stating that this is how it works?
      My Computer


  2. Posts : 821
    Windows 7
       #2

    Windows installation keeps track of which configuration pass is currently running; so if there's an unexpected reboot (crash) -- it restarts to the beginning of the current pass (specialize, auditSystem, auditUser, oobeSystem). Which means it re-runs everything in the same pass all over again.

    Setup doesn't save any run-time progress, that's something you would have to check from an external reg key or written state file.

    If you added a reboot command, then it will loop back to the same point and never get past.

    The only way to guarantee order-of-execution to wrap everything in the same batch script, each line executed by the CALL function, so every command blocks the next one from starting. Your shutdown command would be the last to run.

    https://learn.microsoft.com/en-us/wi...iew=windows-10
      My Computer


  3. Posts : 37
    Windows
    Thread Starter
       #3

    garlin said:
    If you added a reboot command, then it will loop back to the same point and never get past.
    I will read the information in the URL you provided; however, regarding the quoted point, I'm not going to say you're wrong, but here's what I did and what happened:

    ...10 commands (some of which take a while)...
    Command # 11: Create directory c:\before
    Command # 12: shutdown /r /t 0
    Command # 13: Create directory c:\after

    One single reboot, after which both directories existed.

    Then I pushed it farther, thinking maybe the command #13 "snuck in" before the shutdown got ahold of things, so I did:

    ...the first 4 commands from above...
    Command # 5: Create directory c:\before
    Command # 6: shutdown /r /t 0
    ...the remaining 6 commands from above (some of which take a while)...
    Command #13: Create directory c:\after

    The install happened. One reboot. All commands appear to have executed. Both directories exist.
      My Computer


  4. Posts : 821
    Windows 7
       #4

    I'm not saying your way doesn't work. But it's not guaranteed to be safe, since it's a race condition on how long each command takes to execute before shutdown takes effect. If you ran tasks that took longer, would it still work the same way?

    But Windows doesn't tick off the jobs "in order". FirstLogonCommands are executed as RunOnce tasks. If they're started then Windows clears that task from the registry. On reboot, whatever lingering RunOnce tasks will run.
      My Computer


  5. Posts : 37
    Windows
    Thread Starter
       #5

    I'm going to do some more testing on that. Those commands I have after the shutdown take a long time to run, and it didn't restart until all of them had completed.

    But if the system schedules them as runonce commands, then that suggest a way to handle (for example) if one of the commands was to install a software package that required a restart before the next command could be run. It would be fine with the restart, but I would just have to find a way of preventing the next synchronous command until the restart completed.

    I'll post here with more findings.

    - - - Updated - - -

    OK, I don't know why it appeared, earlier, that shutdown "waited" until the rest of commands were complete, but my current testing indicates that shutdown happens in sequence, and the FirstLogonCommands resume after that.

    Now what I need to figure out is whether it does so synchronously. From what I understand, shutdown.exe doesn't directly drive the shutdown process, but just schedules it and then returns. If returning is the "end" of the task, so that the next task is started, then it could be interrupted by the shutdown.

    More info to come...

    - - - Updated - - -

    It turns out the shutdown does interfere with the next command. It appears the way to shutdown synchronously during a FirstLogonCommands sequence is to create a script something like:

    Code:
    shutdown.exe /r /t 0
    cmd.exe /K echo Shutting down
    The "Shutting down" never displays but the /K keeps cmd.exe from returning so that the next synchronous command doesn't start until the shutdown.
      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 14:33.
Find Us




Windows 10 Forums