PC Review


Reply
Thread Tools Rate Thread

Calling CreateProcessWithLogonW from asp.net

 
 
Arne
Guest
Posts: n/a
 
      30th Jul 2003
Hi,
I'm working on an asp.net application that reads a users username and
password, and starts a process with the username read.

The problem is that the program returns value 2(ERROR_FILE_NOT_FOUND).

Here's my code:

public class Class1
{
[DllImport("advapi32.dll", CharSet=CharSet.Auto, SetLastError=true)]
internal static extern bool CreateProcessWithLogonW(String lpszUsername,
String lpszDomain, String lpszPassword, int dwLogonFlags, string
applicationName, string commandLine, int creationFlags, IntPtr environment,
string currentDirectory, ref STARTUPINFO sui, out PROCESS_INFORMATION
processInfo);

[StructLayout(LayoutKind.Sequential)]
internal struct STARTUPINFO
{
internal int cb;
[MarshalAs(UnmanagedType.LPTStr)]
internal string lpReserved;
[MarshalAs(UnmanagedType.LPTStr)]
internal string lpDesktop;
[MarshalAs(UnmanagedType.LPTStr)]
internal string lpTitle;
internal int dwX;
internal int dwY;
internal int dwXSize;
internal int dwYSize;
internal int dwXCountChars;
internal int dwYCountChars;
internal int dwFillAttribute;
internal int dwFlags;
internal short wShowWindow;
internal short cbReserved2;
internal IntPtr lpReserved2;
internal IntPtr hStdInput;
internal IntPtr hStdOutput;
internal IntPtr hStdError;
}

[StructLayout(LayoutKind.Sequential)]
internal struct PROCESS_INFORMATION
{
internal IntPtr hProcess;
internal IntPtr hThread;
internal int dwProcessId;
internal int dwThreadId;
}

const int LOGON_NETCREDENTIALS_ONLY = 2;
const int CREATE_UNICODE_ENVIRONMENT = 0x00000400;
const int NORMAL_PRIORITY_CLASS = 0x00000020;
const int STARTF_USECOUNTCHARS = 0x00000008;


private void Page_Load(object sender, System.EventArgs e)
{

//Method where i keep the html code that all pages use
Webmethods met = new Webmethods();

met.startPage();

string file = Page.Request.Params.Get("filename");
string user = Page.Request.Params.Get("username");
string pw = Page.Request.Params.Get("password");
string domain = Page.Request.Params.Get("domain");
string cmdln = file +" param1 param2"; //file is c:\test.exe

PROCESS_INFORMATION processInfo;

STARTUPINFO startInfo = new STARTUPINFO();

startInfo.cb = Marshal.SizeOf(startInfo);
startInfo.lpTitle = "Command console";
startInfo.dwFlags = STARTF_USECOUNTCHARS;
startInfo.dwYCountChars = 50;

bool ret = CreateProcessWithLogonW(logonName, domain, password,
LOGON_NETCREDENTIALS_ONLY, null, cmdln, NORMAL_PRIORITY_CLASS |
CREATE_UNICODE_ENVIRONMENT, IntPtr.Zero, "C:\\", ref startInfo, out
processInfo);

if ( !ret )
{
Page.Response.Write("<h3><tr><td>Error:&nbsp"+ Marshal.GetLastWin32Error()
+"</td></tr></h3>");
Page.Response.Write("<h3><tr><td>ErrorHR:&nbsp"+
Marshal.GetHRForLastWin32Error()+"</td></tr></h3>");
}
else
Page.Response.Write("<h3><tr><td>ProcessID: {0}&nbsp" +
processInfo.dwProcessId+"</td></tr></h3>");
met.endPage();
}
}

This is what my page prints:

Error: 2
ErrorHR: -2147024894

Any help would be appreciated

Arne


 
Reply With Quote
 
 
 
 
Arne
Guest
Posts: n/a
 
      30th Jul 2003
Sorry, little mistake:

in original code, the CreateProcessWithLogonW method is called with
logonName = user and password = pw.


 
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
Re: CreateProcessWithLogonW Sean Liming \(MVP\) Windows XP Embedded 0 26th Apr 2008 01:55 AM
CreateProcessWithLogonW amdrit Microsoft C# .NET 13 16th Apr 2008 12:32 PM
CreateProcessWithLogonW and ASP.NET =?Utf-8?B?RGF2aWQgRGF2aWRzb24=?= Microsoft C# .NET 10 20th Mar 2007 09:32 AM
CreateProcessWithLogonW =?Utf-8?B?VG9kZCBC?= Microsoft ASP .NET 0 1st Aug 2005 04:28 PM
Calling CreateProcessWithLogonW Benjamin Bittner Microsoft ASP .NET 3 5th Jul 2004 08:11 AM


Features
 

Advertising
 

Newsgroups
 


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