473,569 Members | 2,791 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling CreateProcessWi thLogonW 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_NO T_FOUND).

Here's my code:

public class Class1
{
[DllImport("adva pi32.dll", CharSet=CharSet .Auto, SetLastError=tr ue)]
internal static extern bool CreateProcessWi thLogonW(String lpszUsername,
String lpszDomain, String lpszPassword, int dwLogonFlags, string
applicationName , string commandLine, int creationFlags, IntPtr environment,
string currentDirector y, ref STARTUPINFO sui, out PROCESS_INFORMA TION
processInfo);

[StructLayout(La youtKind.Sequen tial)]
internal struct STARTUPINFO
{
internal int cb;
[MarshalAs(Unman agedType.LPTStr )]
internal string lpReserved;
[MarshalAs(Unman agedType.LPTStr )]
internal string lpDesktop;
[MarshalAs(Unman agedType.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(La youtKind.Sequen tial)]
internal struct PROCESS_INFORMA TION
{
internal IntPtr hProcess;
internal IntPtr hThread;
internal int dwProcessId;
internal int dwThreadId;
}

const int LOGON_NETCREDEN TIALS_ONLY = 2;
const int CREATE_UNICODE_ ENVIRONMENT = 0x00000400;
const int NORMAL_PRIORITY _CLASS = 0x00000020;
const int STARTF_USECOUNT CHARS = 0x00000008;
private void Page_Load(objec t sender, System.EventArg s e)
{

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

met.startPage() ;

string file = Page.Request.Pa rams.Get("filen ame");
string user = Page.Request.Pa rams.Get("usern ame");
string pw = Page.Request.Pa rams.Get("passw ord");
string domain = Page.Request.Pa rams.Get("domai n");
string cmdln = file +" param1 param2"; //file is c:\test.exe

PROCESS_INFORMA TION processInfo;

STARTUPINFO startInfo = new STARTUPINFO();

startInfo.cb = Marshal.SizeOf( startInfo);
startInfo.lpTit le = "Command console";
startInfo.dwFla gs = STARTF_USECOUNT CHARS;
startInfo.dwYCo untChars = 50;

bool ret = CreateProcessWi thLogonW(logonN ame, domain, password,
LOGON_NETCREDEN TIALS_ONLY, null, cmdln, NORMAL_PRIORITY _CLASS |
CREATE_UNICODE_ ENVIRONMENT, IntPtr.Zero, "C:\\", ref startInfo, out
processInfo);

if ( !ret )
{
Page.Response.W rite("<h3><tr>< td>Error:&nbsp" + Marshal.GetLast Win32Error()
+"</td></tr></h3>");
Page.Response.W rite("<h3><tr>< td>ErrorHR:&nbs p"+
Marshal.GetHRFo rLastWin32Error ()+"</td></tr></h3>");
}
else
Page.Response.W rite("<h3><tr>< td>ProcessID: {0}&nbsp" +
processInfo.dwP rocessId+"</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 3414
Sorry, little mistake:

in original code, the CreateProcessWi thLogonW 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
2365
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 to do what I need to do. This appears to work just fine in Windows 2000 and XP with service pack 1, but it doesn't work with XP service pack 2...
2
9348
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, I'm trying to use the Perforce command line utility (p4.exe) to download some files to the local computer. So I set appName="p4.exe" and...
1
5787
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 to call the batch file, it just returns with a return code of 1. When I call cmd.exe, and pass the batch file as a parameter it hangs. After much...
10
5367
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 unsupported command-line virus scanner from Symantec, to check an uploaded file for viruses. At first, I wrapped VPScan with a DLL and ran it as a...
6
1953
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 "Access is Denied" exception. I tried adding the ASPNET account to all the items in the "User Rights Assignment" list but to no avail. The only think...
3
2316
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 i found around the web. but i cant get it to work. It tries to start the application, but it fails. In my eventlog i can see a new info message,...
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 2(ERROR_FILE_NOT_FOUND). Here's my code: public class Class1 {
1
2073
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 it as the parameter. The same environment block works for CreateProcessAsUser, but doesnt give me the same results when used with...
1
4536
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 off. This is the sample program that I am compiling on .NET /* START OF PROGRAM */
0
7605
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7917
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8118
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7962
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5501
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3651
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
933
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.