Been trying to figure this out while also searching the web.
Below is a working code:
bool isCreated = false;
if (requireAdmin)
{
isCreated = CreateProcessWithLogonW(userName.c_str(), domainName.c_str(), userPass.c_str(), LOGON_WITH_PROFILE, NULL, command, 0, NULL, NULL, &startUpInfo, &procInfo);
}
else
{
isCreated = CreateProcessW(NULL, command, NULL, NULL, FALSE, 0, NULL, NULL, &startUpInfo, &procInfo);
}
EXCEPT when supplied with an Administrator that has no password (which is fine with Windows)
So is it possible? I'd like to align with Windows behavior as much as possible unless an official document says otherwise.
Reference with the sort of similar problem (also unanswered): https://forums.codeguru.com/showthread.php?482203-LogonUser-fails-with-empty-password-Why
UPDATE
Additional information:
The function above is called by an application that also requires Admin privileges.
Application - Run As Admin (no password)
Function - using Admin (no password)