The documentation for the CreateDesktop function on msdn describes the following signature:

HDESK WINAPI CreateDesktop( _In_ LPCTSTR lpszDesktop, _Reserved_ LPCTSTR lpszDevice, _Reserved_ DEVMODE *pDevmode, _In_ DWORD dwFlags, _In_ ACCESS_MASK dwDesiredAccess, _In_opt_ LPSECURITY_ATTRIBUTES lpsa ); 

I'm interested in the dwDesiredAccess parameter with type ACCESS_MASK : (documentation) .
More specifically, the value of DESKTOP_HOOKCONTROL .

 DESKTOP_HOOKCONTROL (0x0008L) Required to establish any of the window hooks. 

It turns out that it is needed to establish any hook.

Those. if DESKTOP_HOOKCONTROL not, then it will be impossible to install hooks on the newly created desktop? But this is not the case, I checked.

Then what does this parameter mean?

 private enum DesktopAccess : uint { DesktopNone = 0, DesktopReadobjects = 0x0001, DesktopCreatewindow = 0x0002, DesktopCreatemenu = 0x0004, DesktopHookcontrol = 0x0008, DesktopJournalrecord = 0x0010, DesktopJournalplayback = 0x0020, DesktopEnumerate = 0x0040, DesktopWriteobjects = 0x0080, DesktopSwitchdesktop = 0x0100, GenericAll = (DesktopReadobjects | DesktopCreatewindow | DesktopCreatemenu // | DesktopHookcontrol | DesktopJournalrecord | DesktopJournalplayback | DesktopEnumerate | DesktopWriteobjects | DesktopSwitchdesktop), } CreateDesktop(nameDesktop, IntPtr.Zero, IntPtr.Zero, 0x0001, (uint)DesktopAccess.GenericAll, IntPtr.Zero); 

You can find all code here: https://stackoverflow.com/questions/29902715/how-close-all-process-on-new-desktop

    1 answer 1

    Those. if DESKTOP_HOOKCONTROL is not available, then it will not be possible to install hooks on the newly created desktop? But this is not the case, I checked.

    How did you check this moment?

    If you simply compiled the code from the above link without the DesktopHookcontrol flag, then this doesn’t give anything, since this example switches windows to itself and closes them. DESKTOP_SWITCHDESKTOP and (possibly) DESKTOP_WRITEOBJECTS are sufficient for this.

    DESKTOP_HOOKCONTROL is needed in order to be able to intercept window events using the SetWindowsHookEx function. The given example does not intercept any events and does not use the SetWindowsHookEx function.

    Learn more about the hooks here: https://msdn.microsoft.com/en-us/library/windows/desktop/ms644959%28v=vs.85%29.aspx