CreateProcessWithLogon Vs Runas

P

patanish

Hi,
I am trying to use CreateProcessAsUser() or CreateProcessWithLogonW().
The main application is running under a user login(non admin) and it
needs to start another process(a tool) that needs admin rights. If I
use the "runas" command form the command line to start the tool, it
works fine. But if I use the CreateProcessWithLogonW from my
application, it fails and I get error 1326 -

Logon failure: unknown user name or bad password. ERROR_LOGON_FAILURE

Here is the code snippet - Am I missing something??
Thanks in advance.

PROCESS_INFORMATION piProcInfo;
STARTUPINFO siStartInfo;

// Set up members of STARTUPINFO structure.
ZeroMemory(&siStartInfo, sizeof(STARTUPINFO));
siStartInfo.cb = sizeof(STARTUPINFO);

HRESULT hRes = CreateProcessWithLogonW(_T("user-admin"),
_T("."),
_T("adminPwd"),
LOGON_WITH_PROFILE,
NULL,
cmdline, // application name
NULL, // creation flags
NULL, // use parent's environment
_T("C:\\"), // use parent's current directory
&siStartInfo, // STARTUPINFO pointer
&piProcInfo); // receives PROCESS_INFORMATION
 
Z

zap

1. as there is only UNICODE version of this function don't use _T macro.
Use L"wewewe" instead.

2. lpDomain
[in] Pointer to a null-terminated string that specifies the name of the
domain or server whose account database contains the lpUsername account.
If this parameter is NULL, the user name must be specified in UPN format..
Windows XP: If this parameter is ".", the function validates the account
using only the local account database.

try this
do
{
WCHAR _domain [MAX_COMPUTERNAME_LENGTH + 1];
DWORD l = sizeof _domain;
if (!(_Result = GetComputerNameW (_domain, &l))) break;

LPWSTR
_login = argv[1],
_password = argv[2],
_cmdline = argv[3],
_path = argc > 4 ? argv[4] : NULL;

PROCESS_INFORMATION pi;
_STARTUPINFOW si = { sizeof (_STARTUPINFOW) };

_Result = CreateProcessWithLogonW (_login, _domain, _password,
LOGON_WITH_PROFILE, NULL, _cmdline, NULL, NULL, _path, &si, &pi);

if (!_Result) break;

CloseHandle (pi.hProcess);
CloseHandle (pi.hThread);
}
while (false);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top