Felix Niedermann
Felix Niedermann

Reputation: 319

Executing a .bat file from ASP.NET / VB.NET on the server

I'm trying to execute a batch file, for testing purposes it's called -> test.bat the location of the file is in a Folder named scripts.

Following have I tried:

System.Diagnostics.Process.Start(Server.MapPath("Scripts/test.bat"))

System.Diagnostics.Process.Start("C://......Scripts/test.bat"))

Dim batDir As String = Server.MapPath("C://...../Scripts/") 'And with String format()
proc = New Process()
proc.StartInfo.WorkingDirectory = batDir
proc.StartInfo.FileName = "test.bat"
proc.StartInfo.CreateNoWindow = False 'Don't know what this is, copied it from somewhere.
proc.Start()
proc.WaitForExit()

And I don't get any exception.

Edit 1:

My test.bat should create a folder on the Desktop (Testing purposes).

Edit 2: I'm getting this warning in the Event Log


Event code: 3001

Event message: Request was cancelled.

Event time: 21.07.2020 14:17:09

Event time (UTC): 21.07.2020 12:17:09

Event ID: 4dbd86698e044d2092a89ed01d24f418

Event sequence: 3809

Event occurrence: 4

Event detail code: 0

Application information:

Application domain: xxx 

Trust level: Full 

Application Virtual Path: xxx 

Application Path: C:\xxx

Machine name: xxx

Process information:

Process ID: 8388 

Process name: w3wp.exe

Account name: IIS APPPOOL\DefaultAppPool 

Exception information:

Exception type: HttpException 

Exception message: Request time exceeded.

Request information:

Request URL: http://xxx\mySite.aspx 

Request path: \mySite.aspx 

User host address: xxx 

User:  

Is authenticated: False 

Authentication Type: 

Thread account name: IIS APPPOOL\DefaultAppPool 

Thread information:

Thread ID: 138 

Thread account name: IIS APPPOOL\DefaultAppPool 

Is impersonating: False 

Stack trace: 

Custom event details:


Could it be a Authentication problem?

Upvotes: 1

Views: 592

Answers (1)

ILikeToCode
ILikeToCode

Reputation: 46

Try to add the execution permission to the IIS = "APPPOOL\DefaultAppPool" User and now your folder should be able to be created successfully.

Upvotes: 3

Related Questions