无法让 Request.Querystring 在 VBScript 中传递变量

Cant get Request.Querystring to pass a variable in VBScript

我正在尝试将一个值(在 url 内)传递给 vbscript,然后 vbscript 将使用它来启动可执行文件(在客户端,这就是我使用 vbscript 的原因)将该值作为该可执行文件的参数。例如:

启动此 exe 的语法是

\HQFileServer\Share Launch.exe 1 computername \ServerName

所以我将计算机名传递为 "Name":

http://localhost/launchclient.asp?Name=Laptop1

launchclient.asp 包含:

<script language="vbScript">
set oWshShell = CreateObject("WScript.Shell")
Name = Request.QueryString("Name")
oWshShell.run "\HQFileServer\Share\Launch.exe " & Name & " \SCCM2012WAN",1,True
</script>

我试图通过一次删除一行来调试它,当我意识到,出于某种原因,它似乎没有将查询字符串传递到脚本中。 当我省略 Request.QueryString("Name") 并只输入一个值时 - 它有效...

有什么想法吗?

我试图寻找答案,但无法弄清楚...

更新

好吧,看完后我明白你想做什么了

要将服务器端值传递给客户端代码块,只需在客户端内部使用一个 ASP 代码块,类似这样;

<script language="vbScript">
set oWshShell = CreateObject("WScript.Shell")
oWshShell.run "\HQFileServer\Share\Launch.exe ""<%= Request.QueryString("Name") %>"" \SCCM2012WAN",1,True
</script>

这样 ASP 引擎将在代码块发送到客户端之前替换 <%= Request.QueryString("Name") %> 并且看起来像这样;

<script language="vbScript">
set oWshShell = CreateObject("WScript.Shell")
oWshShell.run "\HQFileServer\Share\Launch.exe "Laptop1" \SCCM2012WAN",1,True
</script>

另外 您需要将其视为 string 值,但因为 VBScript 使用引号 (") 来表示字符串,字符串中的字符串具有要转义,您可以将引号 ("").

加倍

旧答案但仍然相关

Classic ASP 未处理该代码,因为目前它被归类为客户端 (HTML) 脚本块,被忽略并仅通过 "as is"服务器响应。

有两种方法可以解决这个问题:

  1. 通过将 runat="Server" 属性添加到 script 标记,更改脚本标记,使其知道应该由服务器处理。

    <script language="VBScript" runat="Server">
    set oWshShell = CreateObject("WScript.Shell")
    Name = Request.QueryString("Name")
    oWshShell.run "\HQFileServer\Share\Launch.exe " & Name & " \SCCM2012WAN",1,True
    </script>
    
  2. 使用 ASP 代码块。

    <%
    set oWshShell = CreateObject("WScript.Shell")
    Name = Request.QueryString("Name")
    oWshShell.run "\HQFileServer\Share\Launch.exe " & Name & " \SCCM2012WAN",1,True
    %>
    

为了避免与客户端脚本标签混淆,我个人建议使用 ASP 代码块语法 (<% %>).


有用的链接

  • @AnthonyWJones answer to what's the difference between <% %> and <script language=“vbscript” runat=“server”> in classic asp?