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();
Pritam Karmakar
  • 2,773
  • 5
  • 30
  • 49
  • 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)? – SirViver May 14 '11 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. – Pritam Karmakar May 14 '11 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. – Pritam Karmakar May 14 '11 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. – corlettk May 14 '11 at 22:08
  • Oh, and some web-servers are configured to NOT start external processes, as another security precaution. – corlettk May 14 '11 at 22:12
  • Thanks I copied entire tool in App_data folder but still it don't work. Then I tried to run some trusted application like "notepad.exe" and again I see it works in my local machine and pop up a new notepad, but same code does not work from web server. I have changed this line System.Diagnostics.ProcessStartInfo PSI = new System.Diagnostics.ProcessStartInfo("notepad.exe"); – Pritam Karmakar May 14 '11 at 22:19
  • If this doesn't help, you may get better results at serverfault – Brian Webster May 15 '11 at 05:52
  • can you run [ProcessExplorer](http://technet.microsoft.com/en-us/sysinternals/bb896653) filtered to the ASP.NET worker process (w3wp.exe) to see if this is a permissions issue ? its worked for me before. – Menahem May 15 '11 at 06:18
  • any final solution with full source code sample working about it ? – Kiquenet Jul 05 '13 at 10:44

2 Answers2

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.
Brian Webster
  • 30,033
  • 48
  • 152
  • 225
  • 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. – Pritam Karmakar May 16 '11 at 03:04
  • 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. – Pritam Karmakar May 16 '11 at 03:05
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.

Pritam Karmakar
  • 2,773
  • 5
  • 30
  • 49