Diagnostics.Process.Start as another user from ASP.NET 2.0

G

Guest

Here is what I am trying to get to:
I have a console exe that grabs information from the network and writes to
an XML file on the website that web pages then render information from. The
console will be scheduled to run through windows scheduler. However,
sometimes a user may need the information sooner so he/she needs to kick off
the console exe.

The new Process.Start looked teasingly simple. It had a username/password on
the start info. Seemed simple enough.

We created a user with Read/Write/Execute to the folder of the EXE and the
destination folder of the XML files. Both folders are underneath the website.
The network shares are accessable through read-only shares to Everyone.

I get this error: "The application failed to initialize properly
(0xc0000142). Click on OK to terminate the application. when executing it
from ASP.NET.

The dev machine is XP Pro with IIS 5.1 using the default user.

I went so far as to create an empty .NET 2.0 console exe and we get the same
error.

We've logged in to XP as this other credential and can run both EXEs with no
error.

public static void RefreshContent(string filePath)
{
Process processor = new Process();
processor.StartInfo.FileName = filePath;
processor.StartInfo.Arguments = "/q"; //quiet mode
processor.StartInfo.CreateNoWindow = true;
processor.StartInfo.WorkingDirectory =
System.IO.Path.GetDirectoryName(filePath);
processor.StartInfo.UseShellExecute = false;
processor.StartInfo.LoadUserProfile = false; //true also failed.
processor.StartInfo.UserName = "RefreshContentFromWeb";
SecureString password = MakeSecureString("0a8fsud");
password.MakeReadOnly();
processor.StartInfo.Password = password;
processor.Start();

processor.WaitForExit(1000 * 60 * 5); //5 minutes.
}

private static SecureString MakeSecureString(string passwordString)
{
SecureString password = new SecureString();
foreach (char x in passwordString)
{
password.AppendChar(x);
}
password.MakeReadOnly();
return password;
}
 
S

Steven Cheng[MSFT]

Hi Noremac,

For the Process.Start with a specific user, there exists some problem when
executing in ASP.NET application context as I've also met some former
issues discussing on this problem. Currently, the recommended means for
launch a process running under a specific user account is to call unmanaged
API through Pinvoke. Here is a former thread you can reference:

#Run app as specified user from ASP.NET 2.0 Options
http://groups.google.com/group/microsoft.public.dotnet.framework.aspnet/brow
se_thread/thread/51584884d09edfa5/bbfcbd72a6957085

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

That's funny! I was unsuccessful in getting similar code like the post you
provided to work with ASP.NET 1.1 and then I saw references to the
username/password in 2.0 and so I upgraded my code.

Oh well, perhaps I can get the pinvoke unmanaged stuff to work this time
around knowing there is no other way.

Thanks for setting me back on the right path Steven.
 
S

Steven Cheng[MSFT]

Hi Noremac,

I still keep some test projects that contains some code using pinvoke to
call win32 API(createprocessAsUser). If you need, just ping me (through the
email in my signature and remove "online" in it) and I will send you the
test project which you can reference.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Steven Cheng[MSFT]

Hi Noremac,

Any further progress on this? If you need the test project(about using
pinvoke to create new process under specific user), please feel free to
ping me (at "stcheng" + "@microsoft.com").

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top