Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / June 2007

Tip: Looking for answers? Try searching our database.

starting process with alternate credentials causes application error

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DubSport - 22 Jun 2007 21:07 GMT
I am trying to get my .net page to run a simple batch file on my IIS
server. I want it to run with specified credentials. It appears to
start the program cmd.exe as the correct user (shows up in the task
mgr) but it just hangs there and will never finish. Looking in the
event logs I see this:

Application popup: cmd.exe - Application Error : The application
failed to initialize properly (0xc0000142). Click on OK to terminate
the application.

I have no idea why it is hanging like that, can someone help me? Here
is my code:

SecureString pwd = new SecureString();
pwd.Clear();
pwd.AppendChar('1');
pwd.AppendChar('2');
pwd.AppendChar('3');
pwd.AppendChar('4');
pwd.AppendChar('5');
pwd.AppendChar('6');
pwd.AppendChar('7');
pwd.AppendChar('8');
pwd.AppendChar('9');

ProcessStartInfo startInfo = null;
Process batchProcess = null;

startInfo = new ProcessStartInfo();
startInfo.Domain = "somedomain";
startInfo.UserName = "Domainuser";
startInfo.Password = pwd;
startInfo.WorkingDirectory = @"C:\";
startInfo.FileName = "cmd.exe";
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.CreateNoWindow = true;
startInfo.Arguments = @"/c c:\test.bat";
startInfo.ErrorDialog = false;

batchProcess = new Process();
batchProcess.StartInfo = startInfo;
batchProcess.Start();

System.IO.StreamReader myProcessOut = batchProcess.StandardOutput;
string s = myProcessOut.ReadToEnd();
myProcessOut.Close();
batchProcess.WaitForExit(1000);
if (!batchProcess.HasExited)
   batchProcess.Kill();

...Jamie
Nicholas Paldino [.NET/C# MVP] - 23 Jun 2007 20:33 GMT
Is it possible to log in interactively as this user and check to see if
you can run the program under that user account?  Also, if you impersonate
that user for the page (using web.config, or the WindowsIdentity class),
does it work then?

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

>I am trying to get my .net page to run a simple batch file on my IIS
> server. I want it to run with specified credentials. It appears to
[quoted text clipped - 48 lines]
>
> ...Jamie
Willy Denoyette [MVP] - 24 Jun 2007 16:56 GMT
>I am trying to get my .net page to run a simple batch file on my IIS
> server. I want it to run with specified credentials. It appears to
[quoted text clipped - 48 lines]
>
> ...Jamie

The application is hanging because there is a dialog box (invisible!)
waiting for a user action "..Click on OK to terminate...".
What application are you trying to start from test.bat?

Willy.
DubSport - 25 Jun 2007 17:41 GMT
I am able to log in as the specified user and run the .bat file no
problem, it requires no user input at all, and exits automatically.
The .bat file uploads a PDF to a sharepoint site. The specified user
has all necessary permissions from start to finish on files/folders
and sharepoint sites. I have even tried running a very simple dos
command "ipconfig" that requires no user input and same thing, it just
hangs. Is it some sort of security thing with Windows 2003 server
SP2?

I have also tried turning on impersonation in the web.config and also
looked at WindowsIdentity class, neither make a difference.
Anything else you can suggest?

...Jamie
Willy Denoyette [MVP] - 25 Jun 2007 19:06 GMT
>I am able to log in as the specified user and run the .bat file no
> problem, it requires no user input at all, and exits automatically.
[quoted text clipped - 10 lines]
>
> ...Jamie

My guess is that you are running asp.net in the SYSTEM account. Both W2K3
and XP SP2 don't allow you to spawn another process with alternate
credentials when launched from the SYSTEM logon session, you'll need to run
your service (asp.net worker) under the "NetworkService "service account .

Willy.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.