2

I have to run a tool from our internal website. There are few inputs that user will provide from UI and then I want to run the tool with user credential. My code works fine when I run it from my local machine, but when I deploy it to production server and try to execute it from there it does not start anything.

Here is my code, any advice will be greatly appreciated.

            System.Diagnostics.ProcessStartInfo PSI = new System.Diagnostics.ProcessStartInfo(@"D:\run.bat");             
            PSI.UserName = "username";
            PSI.Domain = "domain";
            System.Security.SecureString securePwd = new System.Security.SecureString();
            string password = "password";
            foreach (char c in password)
            {
                // Append the character to the password.
                securePwd.AppendChar(c);
            }
            PSI.Password = securePwd;
            PSI.UseShellExecute = false;
            process.StartInfo = PSI;
            PSI.Arguments = SiteId.Text + " " + WebServiceUrl.Text + " " +LogFile.Text;
            process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            process.Start();
9
  • This may sound silly, but are you sure you have deployed run.bat also to the server (and that the server also has a D:\ drive)? Commented May 14, 2011 at 21:58
  • Yes run.bat is available in that location. When I run it manually after logging in into that server it works fine. Commented May 14, 2011 at 22:02
  • I have admin access to that server as well, so not sure if it is a permission issue, even event log also not logging any error. Commented May 14, 2011 at 22:04
  • +1 for "Permissions". Most prod web-servers are configured to NOT see filesystems outside there "web-content" directories, to avert any possibility of a "upload '../../../etc/shadow'" attack (for instance)... so try putting run.bat somewhere under the prod-server-apps web-content directory. Commented May 14, 2011 at 22:08
  • Oh, and some web-servers are configured to NOT start external processes, as another security precaution. Commented May 14, 2011 at 22:12

2 Answers 2

1

First:

  • Check the identity of your application pool (advanced settings).
  • Switch the identity to "system" and see if the batch file runs from the web app.

If it does:

  • Change the identity back to network service,
  • Make sure your batch file has execute permissions applied for user Network Service (or whichever identity you chose)

If it doesn't:

  • Try opening the file with your code and appending some harmless text to the end.
  • If that works, you can at least rule out permissions and web-app view-ability concerns.
Sign up to request clarification or add additional context in comments.

2 Comments

From yesterday I'm doing lot of research around it. And I can run a notepad.exe from asp.net web page. I have completely removed above code and only use Process.Start("notepad.exe")This start a notepad but when I check it in task manager that process start in Network Service user name. When I replace notpad.exe with my batch file I see same observation. But my application can't run in network service account. So I tried to execute it with specific username & password with this line Process.Start("notepad.exe", "username", securePwd, "domain") and observe it does not start any notepad process.
I have tried this with both app pool identity setting "network service" & "app pool identity" but don't see it executing. Advance thanks if you know anything about it and post it here.
0

I want to close this thread as my problem of running an application from production server solved. But I'm facing issue to run that application using specific user name & password. It always run with whatever identity is set in apppool. So for now if I only use this line it works on app pool default identity

Process.Start("notepad");

But if I use this line of code it don't even start a notepad in that server

            string password = "XXXXX";
            System.Security.SecureString securePwd = new System.Security.SecureString();
            foreach (char c in password)
            {
                // Append the character to the password.
                securePwd.AppendChar(c);
            }
            Process.Start("notepad", "username", securePwd, "domain");

I'm going to ask a separate question on this. Thanks for all who replied.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.