#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <iostream>
int main()
{
STARTUPINFOW startupInfo;
ZeroMemory(&startupInfo, sizeof(STARTUPINFOW));
startupInfo.cb = sizeof(STARTUPINFOW);
startupInfo.dwFlags = STARTF_USESHOWWINDOW;
startupInfo.wShowWindow = SW_SHOWNORMAL;
PROCESS_INFORMATION processInformation;
WCHAR commandLine[MAX_PATH];
lstrcpyW(commandLine, L"C:\\
winnt\\notepad.exe");
BOOL ret = CreateProcessWithLogonW(L"Administrator",
NULL,
L"xxx",
LOGON_WITH_PROFILE,
NULL,
commandLine,
CREATE_DEFAULT_ERROR_MODE,
NULL,
NULL,
&startupInfo,
&processInformation);
if(ret)
{
std::cout << "CreateProcessWithLogonW succeed!" << std::endl;
}
else
{
std::cout << "CreateProcessWithLogonW failed! " << GetLastError() << std::endl;
}
}