473,503 Members | 1,716 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling CreateProcessWithLogonW from asp.net

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
Jul 19 '05 #1
1 3394
Sorry, little mistake:

in original code, the CreateProcessWithLogonW method is called with
logonName = user and password = pw.
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2357
by: jerry | last post by:
I'm trying to run an application under another user within a winform app writen in C#. I have tried a number of different things, but it seems that the CreateProcessWithLogonW function should work...
2
9331
by: Bilal Dinc | last post by:
Hey, I have a question concerning the CreateProcessWithLogonW function imported from the advapi32 dll. For some reason I cant get the appName and cmdLine paramters to work together. For example,...
1
5785
by: Bucky Pollard | last post by:
I have a web service that needs to create a batch file and call it (since there are no APIs for the functionality I am looking for). I am using the Process and ProcessStartInfo objects. When I try...
10
5349
by: David Davidson | last post by:
I am attempting to use CreateProcessWithLogonW from the server-side code of a web page (yes, I want to create a process on the server) and not having much luck. I am attempting to run VPScan, an...
6
1947
by: Matthew Wieder | last post by:
I have an ASPNET app that is running as the ASPNET machine user. It makes a call to the API CreateProcessWithLogonW. On Windows XP it executes without a problem, but on Windows 2000, I get an...
3
2307
by: Benjamin Bittner | last post by:
Hallo NG, I have problems with calling the CreateProcessWithLogonW() function. I tried converting an VB6 example (http://support.microsoft.com/default.aspx?scid=kb;en-us;285879) and some snippets...
2
336
by: Arne | last post by:
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...
1
2063
by: ashu.nitc | last post by:
Hi, I am trying to create a process with the API: CreateProcessWithLogonW. The process (say, CMD.EXE) which gets created doesnt have the environment variables which I have explicitly passed into...
1
4523
by: ashu.nitc | last post by:
Hi , I am trying to create process using CreateProcessWithLogonW() API. This works fine on Win2000 and NT, but in Vista it gives a UAC popup before the process (say, notepad, calc, etc) kicks...
0
7192
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7064
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7261
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7445
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5559
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4665
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3158
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1492
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
369
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.