jmestep
asked on
Run robocopy .bat file from .net web page
We have a robocopy routine that executes every 1/2 hour and synchronizes the files on our load balanced web servers. One of the web designers wants to be able to see the results of his changes without waiting- he has ftp access to Server #1, from where the files get copied to Server #2.
Is it possible to execute the robocopy.bat file from a button on a web page? I saw some solutions in C#, but none in VB.
Thanks
Is it possible to execute the robocopy.bat file from a button on a web page? I saw some solutions in C#, but none in VB.
Thanks
ASKER
One more requirement-
The pages on this website don't use codebehind, so I have to do it with inline code using a button click to start it.
How would I incorporate that?
I've looked for example, but haven't found any so far.
Thanks
The pages on this website don't use codebehind, so I have to do it with inline code using a button click to start it.
How would I incorporate that?
I've looked for example, but haven't found any so far.
Thanks
Here is an example .aspx page that basically only has 1 ASP Button with an onclick event that runs the above code:
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
ExecuteBatchFile("C:\Test. Bat")
End Sub
Private Sub ExecuteBatchFile(ByVal filename As String)
' Define a new process
Dim proc As System.Diagnostics.Process
' Start tge filename you have specified as this new process
proc = System.Diagnostics.Process .Start(fil ename)
' Wait for the batch file to finish
proc.WaitForExit()
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div>
</form>
</body>
</html>
You can then build the rest of your page around the above example.
Regards,
Gary Francis
Software Developer
*** URL removed by humeniuk PE ***
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
ExecuteBatchFile("C:\Test.
End Sub
Private Sub ExecuteBatchFile(ByVal filename As String)
' Define a new process
Dim proc As System.Diagnostics.Process
' Start tge filename you have specified as this new process
proc = System.Diagnostics.Process
' Wait for the batch file to finish
proc.WaitForExit()
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div>
</form>
</body>
</html>
You can then build the rest of your page around the above example.
Regards,
Gary Francis
Software Developer
*** URL removed by humeniuk PE ***
ASKER
I've got the code in and it didn't break the page and I think it's finding the correct file, because if I code in a non-existent file, it says it can't be found.
I think now it's a matter of permissions. I've given ASPNET read and execute, then I tried Everyone with full access permissions on the bat file, but it doesn't copy over. Do you have any suggestions?
I think now it's a matter of permissions. I've given ASPNET read and execute, then I tried Everyone with full access permissions on the bat file, but it doesn't copy over. Do you have any suggestions?
Where is the application running? Is it a server/desktop with IIS? What version of Windows? What version of .Net Framework?
I will also investigate other potential problems.
Gary
I will also investigate other potential problems.
Gary
I have tested this on my server and my code seems to run the file fine.
What I would sugges you do is add a "pause" line into your batch file and check to see any error messages that appear, you may find something in this. Then you just need to monitor this on the web server and step through the pause lines when the batch file executes.
Post back if you need some more information.
Regards,
Gary Francis
Software Developer
*** URL removed by humeniuk PE ***
What I would sugges you do is add a "pause" line into your batch file and check to see any error messages that appear, you may find something in this. Then you just need to monitor this on the web server and step through the pause lines when the batch file executes.
Post back if you need some more information.
Regards,
Gary Francis
Software Developer
*** URL removed by humeniuk PE ***
ASKER
The file and page are on a Windows Server 2003 Web Edition. I'll check with the person who wrote the batch file to see about putting a pause into it.
Thanks
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks,
I'll check into that. The bat file has been running thru the scheduler or manually by itself, I'm just trying to get it set up to run from a web page so we can do it on demand without giving someone else logon permissions to the servers.
I'll check into that. The bat file has been running thru the scheduler or manually by itself, I'm just trying to get it set up to run from a web page so we can do it on demand without giving someone else logon permissions to the servers.
ASKER
I haven't got this completed yet, but I don't want to leave the question open and I think it's a permissions problem now.
C#
public void ExecuteBatchFile(string filename)
{
// Define a new process
System.Diagnostics.Process
// Start the filename you have specified as this new process
proc = System.Diagnostics.Process
// Wait for the batch file to finish
proc.WaitForExit();
}
VB.Net
Public Sub ExecuteBatchFile(ByVal filename As String)
' Define a new process
Dim proc As System.Diagnostics.Process
' Start tge filename you have specified as this new process
proc = System.Diagnostics.Process
' Wait for the batch file to finish
proc.WaitForExit
End Sub
Regards,
Gary Francis
Software Developer
*** URL removed by humeniuk PE ***