Process.Start Doesn't Work

dparkes
dparkes used Ask the Experts™
on
I have an asmx webservice, and want to run an external application.  I have more complex requirements, but for testing purposes, I simply created a test file (test.bat) which copies 1.txt to 2.txt... a simple test that works when run directly.

Instead, the webmethod simply runs and does nothing.  I've tried:

        System.Diagnostics.ProcessStartInfo startInfo = new ProcessStartInfo();
        startInfo.FileName = "c:\\test.bat";
        System.Diagnostics.Process process = Process.Start(startInfo);
        process.WaitForExit();

And I've also tried:

        System.Diagnostics.ProcessStartInfo startInfo = new ProcessStartInfo();
        startInfo.FileName = "c:\\test.bat";
        startInfo.UseShellExecute = false;
        startInfo.Domain = "mydomain";
        startInfo.UserName = "mylogin";
        startInfo.Password = ConvertToSecureString("mypassword");
        System.Diagnostics.Process process = Process.Start(startInfo);
        process.WaitForExit();

The first one does nothing, except I think an svhosts.exe is created.  The second one hangs and does nothing.

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Ashley BryantSenior Software Engineer

Commented:
It's most likely a permissions issue.  ASP.NET by default runs as a user with very little permission to do things outside the scope of the sites.  You can override this by changing the user that ASP.NET impersonates.

Author

Commented:
I do have a local user named aspfilemaker which is part of the administrators group, and that user is in web.config of the root of the server like this:  <identity impersonate="true" userName="MYSERVER\ASPFileMaker" password="mypassword"/>
But my webservices are in a subfolder, not an application, so would they be using that user to impersonate?
Ashley BryantSenior Software Engineer

Commented:
They should be.  Anything that's in your root web.config should apply to the entire site.  Have you tried changing the user at the ASP.NET user runs as at the OS level?  It's probably worth a try just to see if it works.  Though, I wouldn't want to leave it that way unless absolutely necessary.
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

Author

Commented:
I used WindowsIdentity.GetCurrent().Name to confirm that the process is using a local user account that is a memeber of the administrators group.  Still doesn't work.
Senior Software Engineer
Commented:
I've taken a look at a few other sites about this issue.  The majority of the recommendations are to create a windows service to run your process and tell that service to run from ASP.NET.

Author

Commented:
Sorry I don't totally understand what you mean by run from ASP.Net.  How do I do that?
Also, I read that I can't .bat files with Process.Start so I tried:
System.Diagnostics.Process.Start("cmd.exe", "/C C:\\test.bat");
...which also didn't work for me.
 I'm confused about this creating a windows service idea.  Could you give me a link to one of these sites?
 

Author

Commented:
It just occured to me that 'run from Asp.Net' might mean to run it from codebehind or from a .aspx file?  However, I need to use a webservice since I'm interfacing with a Flex application.  At the moment I'm just running the webservice straight from the server for testing though.

Author

Commented:
Ok, I see what you mean about creating a service with permissions.  Luckily, I found a workaround, but thanks.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial