Executing a batch file from C #

I have a batch file to execute a VB script. Although double-clicking the batch file will work, but when I did the same with C #, it worked in my local environment, but not on the intermediate server (Windows 2008r2 server). Is there any permission level that I need to apply for this execution? From an intermediate server I can double click and execute the batch file ...

I logged in to the server with an administrator account and viewed the application as localhost.

Is there something that I am missing when executing a batch file with C #,

I don’t think there are any problems with my C # code, since it works fine in my local environment, anyway, this is my C # code,

if (File.Exists(FileName*)) { System.Diagnostics.ProcessStartInfo p = new System.Diagnostics.ProcessStartInfo(FileName); System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.StartInfo.FileName = FileName; proc.StartInfo.RedirectStandardError = true; proc.StartInfo.RedirectStandardOutput = true; proc.StartInfo.UseShellExecute = false; proc.Start(); proc.WaitForExit(); } else { lblMsg.Text = "Sorry unable to process you request"; } 

* FileName is the path to the batch file. In addition, I set full permission to folders that contain batch and vbs files.

+8
c # vbscript batch-file windows-server-2008-r2
source share
2 answers

To do this, your application pool must be launched as a user with access to the batch file. Check how to change the application pool identifier for IIS 7 or IIS 6 .

+3
source share

To find out what Karteek said:

  • In application pools, IIS 7 runs as the application pool account, IISAPPPOOL\AppPoolName
  • IIS 6 runs as Network Service application pools
  • In any case, these accounts do not have access to the user documents folder and (by default) can only read from regular data stores.

Typically, you want to save the account for the application pool, since it helps to segregate the data, so I would just make sure that you granted read permissions + execution for the bat file needed for the application pool account. You will also need the correct permissions for any padding / folders the bat should read / write with.

You do not need to change anything in your application in order to fix this problem if you do not want the IIS application to disguise itself as a user who is actually sitting on the website (it really works only if you use some form of authentication.) this is a bad idea - so it’s best to set permissions.

Typically, when working on a web server, you want the permission / execution levels to be as low / restrictive as possible.

+2
source share

All Articles