SetThreadDesktop function (winuser.h)

Assigns the specified desktop to the calling thread. All subsequent operations on the desktop use the access rights granted to the desktop.

Syntax

BOOL SetThreadDesktop(
  [in] HDESK hDesktop
);

Parameters

[in] hDesktop

A handle to the desktop to be assigned to the calling thread. This handle is returned by the CreateDesktop, GetThreadDesktop, OpenDesktop, or OpenInputDesktop function.

This desktop must be associated with the current window station for the process.

Return value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

The SetThreadDesktop function will fail if the calling thread has any windows or hooks on its current desktop (unless the hDesktop parameter is a handle to the current desktop).

Warning  There is a significant security risk for any service that opens a window on the interactive desktop. By opening a desktop window, a service makes itself vulnerable to attack from the logged-on user, whose application could send malicious messages to the service's desktop window and affect its ability to function.
 

Requirements

Requirement Value
Minimum supported client Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header winuser.h (include Windows.h)
Library User32.lib
DLL User32.dll
API set ext-ms-win-ntuser-windowstation-l1-1-0 (introduced in Windows 8)

See also

CreateDesktop

Desktops

GetThreadDesktop

OpenDesktop

SetProcessWindowStation

Window Station and Desktop Functions