PC Review


Reply
Thread Tools Rate Thread

CreateProcessWithLogon Vs Runas

 
 
patanish
Guest
Posts: n/a
 
      21st Apr 2004
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
 
Reply With Quote
 
 
 
 
zap
Guest
Posts: n/a
 
      21st May 2004
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);

--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
runas /user:USER problem and a strange behavior of runas Stefan Helmig Windows Vista Administration 1 31st Jan 2007 07:51 PM
"Application failed to intialize" with CreateProcessWithLogon =?Utf-8?B?U3RldmU0RA==?= Microsoft C# .NET 6 13th Apr 2006 04:33 PM
CreateProcessWithLogon and managed Processes =?Utf-8?B?RXJpYyBMaXZpbmdzdG9u?= Microsoft Dot NET 2 16th Sep 2005 03:10 PM
CreateProcessWithLogon\AdjustTokenPrivileges on Win2K Vincent Finn Microsoft Dot NET 4 30th Jun 2004 01:13 PM
CreateProcessWithLogon on Win2000 Vincent Finn Microsoft VB .NET 0 18th Jun 2004 05:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:01 PM.