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: " + 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} " +
processInfo.dwP rocessId+"</td></tr></h3>");
met.endPage();
}
}
This is what my page prints:
Error: 2
ErrorHR: -2147024894
Any help would be appreciated
Arne 1 3421
Sorry, little mistake:
in original code, the CreateProcessWi thLogonW method is called with
logonName = user and password = pw. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
installed.
I'm sure it's one of the "Enhanced security features" of service pack
2, but I can't...
|
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 cmdLine="print -o
\"c:\\file.txt\" -q \"//depot/files/file.txt\"". So then I call...
|
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 frustration and aggrevation,
I found that CMD IS in fact running, but it is running under the context...
|
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 COM+ component and found that it would work
only when someone was logged on and it was set to run...
|
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
that work was adding the ASPNET account to the local admin group; then
it executed perfectly. ...
| |
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, everytime i execute my code. i try to translate it, cause i have a
german windows installed, so it...
|
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
{
|
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 CreateProcessWithLogonW(). The difference in
the list
|
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 */
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |