从 IIS (ASP) 在服务器上运行 VBS 脚本 [英] Running VBS script on server from IIS (ASP)

查看:30
本文介绍了从 IIS (ASP) 在服务器上运行 VBS 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从服务器 (IIS-6) 上的 ASP 文件中运行 VBS 文件我已经更改了安全性,因此必须登录到服务器才能访问 ASP 页面(这样才能授予 ASP 访问 VBS 文件存储位置的权限).

I am trying to run a VBS file from within an ASP file on a server (IIS-6) I have changed the security so one have to login to the server to access the ASP-page (this so that ASP is given permission to the place where the VBS files are stored).

所以,我有一个看起来像这样的 default.asp 页面:

So, I have a default.asp page that looks like this:

<%response.write "hello" 'just for debugging purposes.
set objshell = server.createobject("wscript.shell")
objShell.Run "c:	est	est.vbs",0,true '0=no interaction, true=wait for command to finish%>

VBS 文件只是一个空文件(一些备注)所以应该发生的是 wscript 应该运行,什么都不做,关闭 wscript.exe 并返回它已完成.

The VBS file is just an empty file (some remarks) so what SHOULD happen, is the wscript should run, do nothing, close wscript.exe and return that it is done.

上面例子中发生的事情是在服务器上启动 wscript.exe,网页等待命令完成.但是 wscript.exe 永远不会自行退出/停止.如果我结束 wscript.exe 进程,那么页面将继续加载.但是 VBS 不会被执行.

What happens in the above example is that on the server wscript.exe starts, and the webpage waits for the command to finish. But the wscript.exe never quits/stops by itself. If I end the wscript.exe process then the page will continue loading. But the VBS will not have been executed.

于是我尝试了一些修改,我在VBS文件中添加了代码,写了一个带有执行时间的文件,所以我知道它并没有运行VBS文件.

So I have tried a few modifications, I added code to the VBS file to write a file with the time of the execution, so I KNOW that it does not run the VBS file.

我还尝试了 objshell.run/exec 命令的其他变体:

I have also tried other variants of the objshell.run/exec commands:

objsshell.exec("cscript.exe /B /H:Cscript c:	est	est.vbs") ' nothing happens at all.
objsshell.exec("wscript.exe /B /H:Cscript c:	est	est.vbs") ' wscript and "hangs"

有人对如何运行 VBS 命令以及退出 Wscript.exe 进程有任何提示吗?

Anyone have any tips on how I get the VBS command to run, and the Wscript.exe process to exit?

推荐答案

经过几个小时的摆弄,我想回答我自己的问题,因为我认为我的发现会比我更有趣.

I would like to answer my own question after a couple of hours of fiddling about, because I think my findings will be interesting for more than me.

  1. 要了解正在发生的事情,请转到服务",选中万维网服务的与桌面交互"框.这样,所有错误和消息框都会显示在控制台上.

通过编写以下小的 asp 页面,我们得到了一个控制台/cmd 窗口来进行一些测试:

By writing the following small asp-page we got a console/cmd-window to make som tests with:

<%
set objshell=server.createobject("WScript.Shell")
objshell.run "cmd.exe"
%>

当你与与桌面交互"一起这样做时,你会得到一个命令行窗口,如果你在这个窗口中写

When you do this along with "interact with desktop" you get a Commandline window and if you in this window write

echo %userprofile%

您获得了运行 cmd 窗口的用户.在我们的例子中,它是默认用户".

You get the user that is running the cmd-window. In our case it was "Default User".

  1. 在测试运行 vbs 脚本时,我们发现默认用户"没有注册 wscript.dll,我们也无法注册它.我们从未深入了解原因.

  1. while testing to run vbs scripts we found that "Default user" didnt have the wscript.dll registered, and we couldnt get it to register either. We never got into why.

Cscript 然而不需要注册,并且与桌面的交互也较少,因此可以停止脚本的事情较少.我们还发现您需要 VBS 文件中请求的所有文件的完整路径(这可能是大问题之一,因为我们使用的是相对路径).

Cscript however did not need to be registered, and also had less interaction with the desktop, so less things that could stop the script. We also found that you need the FULL PATH to all files requested in the VBS file (this was probably one of the big issues, as we worked with relative paths).

所以经过大量的摆弄之后,最终起作用的 ASP 代码等待 VBS 脚本完成它的工作,然后继续加载页面:

So after a lot of fiddling, the final ASP-code that works, waits for the VBS-script to do its thing, then continues to load the page is:

<%
set objshell=server.createobject("WScript.Shell")
objshell.run "cmd.exe /c ""cscript c:	est	est.vbs " + request("any_parameters") + " Another_hardcoded_parameter""",1,true
set objshell=nothing
response.redirect("/a_new_page_with_info_from_vbs_file.asp")
%>

使用 Windows 集成身份验证或将可以访问这些文件的用户设置为网站的匿名用户,该网站可以正常工作,但不是很安全.

Use either windows integrated authentication or set a user with access to these files as the anonymous user for the website which works, but is not very safe.

这篇关于从 IIS (ASP) 在服务器上运行 VBS 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆