问题
I am trying to execute a .bat to launch notepad.exe on my localhost(server-side) with the following code:
index.asp
<%
set wshell = CreateObject("WScript.Shell")
return = wshell.run("c:\file.bat", 4, false)
response.write(return)
set wshell = nothing
%>
file.bat
notepad.exe
When I open the ASP page, nothing happens. A value 0 is returned because of the variable "return". So I tried set the false value to be true, and then the server froze and didn't return anything; I think that happened because there were no values to be returned from the .bat file. I tried also running the notepad.exe (C:\Windows\notepad.exe) directly instead of using a .bat file but still nothing happened. I also tried using ASPExec.dll but to no avail either.
Does anyone know what I am doing wrong?
More info:
My local web server is IIS7 that comes with Windows 7. I am doing this on localhost just for testing purposes. I have to accomplish this in Classic ASP because eventually I will have to import the website to a WinCE7 device. I am aware that WshShell is not available for WinCE but for now I am just trying to see if it works. Eventually I will need to be able to run a .exe that installs updates on the device through the website.
回答1:
Your code is running as a non-interactive IIS user; it cannot interact with the local desktop.
来源:https://stackoverflow.com/questions/7423294/classic-asp-running-exe-from-a-web-page-on-localhost