The CreateProcessWithLogonW function may fail when you call it by setting lpDomain to a Microsoft Entra ID (formerly known as Azure Active Directory) account in UPN format.
Symptoms
The CreateProcessWithLogonW function documentation states that the lpDomain parameter must be set to NULL if lpUsername is in UPN format.
However, the CreateProcessWithLogonW function may fail, and the GetLastError function returns ERROR_LOGON_FAILURE (1326) or another error code on Windows 10 and Windows 11 when the following conditions are met:
-
The
lpUsernameparameter is set to a Unicode string containing a Microsoft Entra account, specified in UPN format. -
The
lpDomainparameter is set toNULL.
Cause
Microsoft has confirmed this is a problem in Windows 10 and Windows 11.
Workaround
To work around this issue, follow these steps:
-
Call
CreateProcessWithLogonWby setting thelpUsernameparameter to a user account in UPN format and thelpDomainparameter toNULL. -
If step 1 fails, call
CreateProcessWithLogonWagain with thelpDomainparameter set toAzureAD.
Source: Microsoft Learn / IT Pro troubleshooting by Microsoft and contributors (upstream author metadata: cts-davean). Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.
