SHCreateSessionKey

This function opens a registry key for per-session settings.

Declaration

HRESULT
SHCreateSessionKey (
    REGSAM samDesired,
    HKEY *phKey);

Parameters

The samDesired argument specifies access rights that are desired to the key.

The phKey argument is the address of a variable that is to receive a handle to the opened key.

Return Value

The function returns zero for success, else an error code.

Behaviour

The function opens a key in which to store information for the current session:

Key: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\SessionInfo\session

where session is a decimal representation of the current session ID. This key is ordinarily created (afresh) by USERINIT.EXE before starting the shell. This function, despite its name, merely opens the key.

A potentially signficant use for the session key is provided by the general support for namespace extensions. Where a registry folder allows for namespace extensions to be defined in a subkey of the Explorer key, it also allows for namespace extensions in the same subkey relative to the session key. For instance, a run-once program may add a key

Key: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\SessionInfo\session\Desktop\Namespace\{clsid}

to define an extension to the desktop’s namespace just for the current session.

Availability

The SHCreateSessionKey function is exported from SHELL32.DLL as ordinal 723 in version 6.00 and higher.

Though this function dates from 2001, it was still not documented by Microsoft as late as the January 2007 edition of the Windows Vista Software Development Kit (SDK).