none
How to edit and update programmatically gpedit.msc in windows 10 using c# RRS feed

  • Question

  • I need to modify two entries of the gpedit.msc from C#, is it possible? This entries I need to disable:

    Computer Configuration\Administrative Templates\System\Power Management\Sleep Settings\Require a password when a computer wakes (plugged in)
    Computer Configuration\Administrative Templates\System\Power Management\Sleep Settings\Require a password when a computer wakes (on batettery)
    I have a .net app which turns off / on the screen using the Win32 api, and, when the screen turns on, it goes to the lock screen, so i need to disable the mentioned entries to avoid locking the screen. I need to do it programatically.

    So, my question is:

    Is it possible to edit the gpedit.msc from C#? How?
    If it's not possible to edit the gpedit, I could modify the regedit, but i don't know this gpedit entries are associated with which regedit entries (or if i have to add new, where?)

    sandeep chauhan

    Monday, December 17, 2018 3:19 PM

All replies

  • On my OS (Windows 10),

    it adds (for plugged in), among other keys, the key in HKEY_USERS

    "[User SID]\\Software\\Microsoft\\Windows\\CurrentVersion\\Group Policy Objects\\{92FCBEC5-915C-4AFB-8661-77E836D02F23}Machine\\Software\\Policies\\Microsoft\\Power\\PowerSettings\\0e796bdb-100d-47d6-a2d5-f7d2daa51f51"

    with the value

    "ACSettingIndex" set to 1

    If I change it to 0, it displays disabled in GpEdit (but I cannot test if it changes when the computer wakes)

    (the normal way would be with PowerWriteACValueIndex (with GUID_LOCK_CONSOLE_ON_WAKE) but it returns 

    ERROR_ACCESS_DISABLED_BY_POLICY because of various keys added by GpEdit)


    • Edited by Castorix31 Tuesday, December 18, 2018 10:26 AM
    Tuesday, December 18, 2018 10:25 AM
  • For the most part, GPEDIT is just a front-end on the registry, and modifying the registry is quite easy to do from C#. The trick is figuring out which registry entries correspond to GPEDIT settings. You can accomplish this using the SysInternals ProcMon tool by having ProcMon monitor registry access for your GPEDIT process, and then change the fields you are interested in. Look at the ProcMon log to see which fields changed in the registry.

    Components that have enabled registry monitoring will be notified when you change the registry, while others probably won't know until they next scan the registry, which may only be on boot. I don't know whether the power manager will notice your changes, but if modifying them by hand via GPEDIT works, then modifying those values in the registry directly should work.

     -Brian


    Azius Developer Training www.azius.com Windows device driver, internals, security, & forensics training and consulting. Blog at www.azius.com/blog

    Tuesday, December 18, 2018 6:47 PM
    Moderator