CreateWindowStation function

Creates a window station object, associates it with the calling process, and assigns it to the current session.


HWINSTA WINAPI CreateWindowStation(
  _In_opt_ LPCTSTR               lpwinsta,
           DWORD                 dwFlags,
  _In_     ACCESS_MASK           dwDesiredAccess,


lpwinsta [in, optional]

The name of the window station to be created. Window station names are case-insensitive and cannot contain backslash characters (\). Only members of the Administrators group are allowed to specify a name. If lpwinsta is NULL or an empty string, the system forms a window station name using the logon session identifier for the calling process. To get this name, call the GetUserObjectInformation function.


If this parameter is CWF_CREATE_ONLY and the window station already exists, the call fails. If this flag is not specified and the window station already exists, the function succeeds and returns a new handle to the existing window station.

Windows XP/2000:  This parameter is reserved and must be zero.

dwDesiredAccess [in]

The type of access the returned handle has to the window station. In addition, you can specify any of the standard access rights, such as READ_CONTROL or WRITE_DAC, and a combination of the window station-specific access rights. For more information, see Window Station Security and Access Rights.

lpsa [in, optional]

A pointer to a SECURITY_ATTRIBUTES structure that determines whether the returned handle can be inherited by child processes. If lpsa is NULL, the handle cannot be inherited.

The lpSecurityDescriptor member of the structure specifies a security descriptor for the new window station. If lpsa is NULL, the window station (and any desktops created within the window) gets a security descriptor that grants GENERIC_ALL access to all users.

Return value

If the function succeeds, the return value is a handle to the newly created window station. If the specified window station already exists, the function succeeds and returns a handle to the existing window station.

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


After you are done with the handle, you must call CloseWindowStation to free the handle.


Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]


Winuser.h (include Windows.h)





Unicode and ANSI names

CreateWindowStationW (Unicode) and CreateWindowStationA (ANSI)

See also

Window Station and Desktop Functions
Window Stations



Community Additions

© 2015 Microsoft