batch file execution asp classic

2019-08-30 10:55发布

问题:

I need help executing a batch file from a client (accessing via HTTP intranet executing using ASP Classic).

OS used:

  • Client (Windows XP) - Here is where the user will access the HTML page.
  • Server (Windows server 2003) - Here is where the folder is being created including the batch file. This is also where the ASP pages and HTML pages is stored and run through IIS

Scenario:

The user will access an HTML page that is linked to an asp page....

HTML code:

<html>
<body>
<form method="GET" action="default.asp">
Name<input type="text" name="firstname"/>
Uname<input type="text" name="username"/>
Fulname<input type="text" name="fullname"/>
Pass<input type="text" name="password"/>
Qwarning<input type="text" name="qwarning"/>
Qlimit<input type="text" name="qlimit"/>
<input id="submit" type="submit" value= "submit" />
</form>
</body>
</html>

After filling the forms the following asp codes will execute.
-The following code will create a folder and create a batch file that will create a user account and set its account permission

ASP CODE:

<%
'Folder Creation
dim fs
Dim name,uname,fulname,pass,qlimit,qwarning

name = Request.QueryString("firstname")
uname = Request.QueryString("username")
fulname = Request.QueryString("fullname")
pass = Request.QueryString("password")
qlimit = Request.QueryString("qlimit")
qwarning = Request.QueryString("qwarning")


'Batch File Creation
set fs=Server.CreateObject("Scripting.FileSystemObject")
if NOT fs.FolderExists("c:\dept\" & name ) Then 
fs.Createfolder("c:\dept\" & name)
response.write name &" successfully created"
else
response.write name &" is already exist!"

end if
set fs=nothing

dim fsc,cfile
set fsc=Server.CreateObject("Scripting.FileSystemObject")
set cfile=fsc.CreateTextFile("c:\dept\" & name & ".bat")

'User Creation
cfile.writeline("echo off")
cfile.writeline("cd\")
cfile.writeline("Net User " & uname & " " & pass & " /add /comment:""Created by Mystic System"" /expires:never /fullname:""" & fulname & """ /passwordchg:no")
cfile.writeline("WMIC USERACCOUNT WHERE ""Name='" & uname & "'"" SET PasswordExpires=False")

'USER QUOTA
cfile.writeline("fsutil quota modify c: 104857600 209715200 WINDOWS-GDKLDNY\" & uname)


'Creation OF Permision to folder
cfile.WriteLine("cacls c:\dept\" & name & " /e /P Administrator:F")
cfile.WriteLine("cacls c:\dept\" & name & " /e /P " & uname & ":R")
cfile.WriteLine("cacls c:\dept\" & name & " /e /G " & uname & ":W")
cfile.WriteLine("del /a " & "c:\dept\" & name & ".bat")

cfile.close

set cfile=nothing
set fsc=nothing
set perm=nothing

set wshell = CreateObject("WScript.Shell") 
wshell.run "c:\dept\" & name & ".bat" 
set wshell = nothing

%>

ERRORS:

"No errors has been displayed."

-I have already grant the IUSR,IWAM,IIS_WPG including the NETWORK SERVICE full permission to the root folder due to desperation.. :(

Problem:
The batch file is not executing or maybe not being read (its like the batch file is not opening to execute its content). If i run it manually or hit enter on the batch file it runs perfectly. What seems to be the problem? is it on my ASP?

-I've already monitored the process or the file being accessed by the client using "Filemon" application and the results are all success from the w3wp.exe and cmd.exe. -I've tried creating a vbscript to execute that batch and the vbscript is being called by the asp.
Still no luck. :(

回答1:

From my experience WScript.Shell only really worked with IIS 5, might I suggest another way to execute the batch file:

If you have access to SQL:

How can I run sqlcmd.exe from an ASP page?

If you can register a COM:

http://www.shotdev.com/asp/asp-run-execute-exe/asp-execute-exe-wscript-shell/

Source: Trying to launch photoshop with scripting



回答2:

Another option -- especially if you need to run these scripts under a different security context than IIS for folder/share access, running Admin-privileged commands, etc. -- is to set up a Windows Scheduled Task to run the script (without any associated schedule if it doesn't need one), and then call that task from the ASP page.

Run a scheduled task from an ASP/IIS page

It does require granting filesystem access to the IUSR account on the scheduled task file.



标签: asp-classic