Link to home
Start Free TrialLog in
Avatar of dparkes
dparkesFlag for United States of America

asked on

Process.Start Doesn't Work

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.

Avatar of Ashley Bryant
Ashley Bryant
Flag of United States of America image

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.
Avatar of dparkes

ASKER

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?
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.
Avatar of dparkes

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Ashley Bryant
Ashley Bryant
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dparkes

ASKER

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?
 
Avatar of dparkes

ASKER

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.
Avatar of dparkes

ASKER

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