none
Windows 10 new shut down options RRS feed

  • Question

  • The latest Windows 10 update offers additional shutdown options:


    Sign out

    Sleep

    Update and shut down

    Shut down

    Update and restart

    Restart


    How can these new options, especially (Update and shut down and Update and restart) be chosen programatically by C# or VB.NET from a windows service based on .Net 4.0 ?


    Please help!

    Thanks!

    Thursday, July 5, 2018 4:29 PM

All replies

  • But how can I select this options from code?

    Friday, July 6, 2018 3:59 AM
  • Hi evpwpm

    There is about locking, logging off , rebooting, shutting down, hibernating and putting the system on stand by mode in .Net. Here we are going to use both unmanaged code and .Net framework for these functions.

    Locking

    <DllImport("user32.dll")>

    Public Shared Sub LockWorkStation()

    Logging off

    <DllImport("user32.dll")>

    Public Shared Function ExitWindowsEx(ByVal uFlags As Integer, ByVal dwReason As Integer) As Integer

    Double click the log off button and add the following function call to the event. Flag 0 indicates logoff,

     

    ExitWindowsEx(0, 0)

     

    To force processes to terminate while logging off, change the flag to 4 in the function as below:

     

    ExitWindowsEx(4, 0)

     

    Rebooting

    To reboot we are going to use the same function ExitWindowsEx but with a different flag. Add the following code to the click event handler of the reboot button.

    Shutdown

     

    Now add the following code to the button Shutdown's click event handler.

     

    ExitWindowsEx(1, 0)

     

     

    Hibernate and Standby

    // Hibernate

    Application.SetSuspendState(PowerState.Hibernate, true, true)

    // Standby

    Application.SetSuspendState(PowerState.Suspend true, true)

     

    But I am not sure about the update. Have you learned UI Automation? It seems to be able to simulate a mouse function, you can click any button on the desktop.

    Best Regards

    Alex


    MSDN Community Support Please remember to click &amp;amp;amp;quot;Mark as Answer&amp;amp;amp;quot; the responses that resolved your issue, and to click &amp;amp;amp;quot;Unmark as Answer&amp;amp;amp;quot; if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, July 6, 2018 6:06 AM
  • Hi Alex,

    first of all, I very much appreciate your help!

    Now my point is: I'm already using this function calls / APIs as you've described.

    The system  reboots  but if there are pending updates awaiting reboot, they get  not  installed after this type of reboot.

    If I select "Update and restart" manually from the shutdown options of Windows the updates are insalled during the rebbot phase and all is fine!

    This is exactly what I'm looking for to happen also by code, install any pending updates that await a restart to get installed.


    Any more ideas?

    Many thanks!


    Friday, July 6, 2018 7:27 PM
  • Updates are checked and installed with WUA API (WUApiLib)
    Friday, July 6, 2018 9:21 PM
  • Thanks, this could be the right direction.

    Does anybody know if Windows can be configured in that way that downloaded Updates are installed at every restart ( so one doesn't need explicitly to select  Update and restart - but just restart?

    Thanks!

    Saturday, July 7, 2018 6:08 AM
  • The InitiateShutdown function  allows you to request the installation of pending updates by specifying the SHUTDOWN_INSTALL_UPDATES flag.


    • Edited by RLWA32 Saturday, July 7, 2018 2:55 PM fix link
    Saturday, July 7, 2018 2:52 PM