Execute bat file from asp.net on my IIS server


I have code looking like this:
 Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


        Dim psi As New System.Diagnostics.ProcessStartInfo("C:\batfiles\move2.bat")
        psi.RedirectStandardOutput = True
        psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden
        psi.UseShellExecute = False
        Dim listFiles As System.Diagnostics.Process
        listFiles = System.Diagnostics.Process.Start(psi)
        Dim myOutput As System.IO.StreamReader = listFiles.StandardOutput
        If listFiles.HasExited Then
            Dim output As String = myOutput.ReadToEnd()
            Me.processResults.Text = output
        End If
    End Sub

Open in new window

I execute the code on my local machine and the bat file is executed and everything works fine.

Then I try to do the same on my MS server 2012 IIS, but then nothing happens. The file is not executed.

I tried to alter the security of the folder where the bat file resides and give IIS_USERS permissions, but nothing happens.

What more can I try?

Thanks for help!

Peter NordbergIT ManagerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David Johnson, CD, MVPOwnerCommented:
IIS_USERS permissions  (does it have execute permissions?) also needs permissions on the source and destination folders that your batch file references.
ste5anSenior DeveloperCommented:
Basically, I consider this a bad idea. Can you please explain what is the purpose of your batch file?
Peter NordbergIT ManagerAuthor Commented:
I need to execute some move of files when they execute some commands in the webappöication. The files are so big (10-20GB) so they can not be moved with the file.move command within asp.net.

Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

ste5anSenior DeveloperCommented:
My architectural senses are tingling. Can you describe the concrete context?

You should neve move such files on the application server.

When you really need to work on physical files here, I would use a Windows service which could be remoted. To get an appropriate separation of privileges.
Peter NordbergIT ManagerAuthor Commented:
How can I use a Windows service to do that and is it possible to trigger it from the application?

ste5anSenior DeveloperCommented:
I would use a Windows service to self-host a WCF service.

But: Can you describe the concrete context?

It really is only guess. So more information would be really nice. It really depends on the workflow.
Peter NordbergIT ManagerAuthor Commented:
I have a web application where producers are uploading and manage the files that are going to be used for playout of a tv station.

In the application you can change status of the file (uploaded, approved, rejected, scheduled, archived etc.). Each status has a physical representation in the form of a folder in the network storage.

I would like to be able to move the file to the different folder destinations when the status is changed in the application.

So if a file has a status of Uploaded and then is residing in the Upload folder and the status is changed to Approved, it would automatically trigger a move of the file from Upload to Approved folder.

ste5anSenior DeveloperCommented:
Okay, so you have a relativly small user base here.

Then I would go an easier way: Create a new account for your IIS app pool, which has the necessary permissions. Then run you application in an app pool with this user account.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.