如何从网站执行vbscript [英] how to execute vbscript from website

查看:52
本文介绍了如何从网站执行vbscript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个VBScript文件.当它在计算机上时,它可以正常工作.我想将其放在php站点上,以通过单击按钮执行它.但是我没有成功.它实际上获得了计算机信息.希望它可以在用户计算机上运行.任何想法将不胜感激.如果或者是否有人知道如何使用jscript

i have a VBScript file. When its on the computer it works fine. I want to put it on a php site for it to be executed by a button click. but i have not been successful. it actually get computer info. hoping it will work on the users machine. any ideas will be appreciated. If or if anyone knows how to do it with jscript

这是代码:

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colSettings = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colSettings 
    Wscript.Echo "OS Name: " & objOperatingSystem.Caption
    Wscript.Echo "Version: " & objOperatingSystem.Version  
    Wscript.Echo "Available Physical Memory: " & _
        objOperatingSystem.FreePhysicalMemory
Next

Set colSettings = objWMIService.ExecQuery _
    ("Select * from Win32_ComputerSystem")
For Each objComputer in colSettings 
        Wscript.Echo "Total Physical Memory: " & _
        objComputer.TotalPhysicalMemory
Next

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")

Set colSettings= objWMIService.ExecQuery _
    ("SELECT * FROM Win32_DiskDrive")
For Each objItem In colSettings
      WScript.Echo "Disk Size: " & objItem.Size 
   Next

Dim WSHShell 
Dim objAdr 
On error resume next 
Set WSHShell = WScript.CreateObject("WScript.Shell") 
test = wshshell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names") 
If err.number > 0 Then 
msgbox "SQL Server not found" 
else msgbox "SQL Server found" 
end if 

推荐答案

如果您(尤其是chloe的老板)同意,则

If you (and especially chloe's boss) agree, that

  • 网站不应在客户的计算机上进行间谍
  • 用户有权获得一些有关他将要安装的软件的系统要求的帮助
  • 此类帮助不应涉及降低安全设置

您的选择是

  • 列出要求并详细说明如何确定要求
  • windows:向用户(下载)提供HTA的源(
  • list the requirements and give detailed instruction how to determine them
  • windows: offer the user (to download) the source of a HTA (HTML Application) that generates/shows an appropriate report
  • unix/linux: offer the user (to download) the source of a script (pick at least two popular languages) that generates/shows an appropriate report
  • given that you'll write an installer anyway that will check requirements, you can bundle those checks into an independent "make sure of the requirements" application

如果您认为适合使用HTA,请这样说,我将在此答案中予以补充.

If you decide a HTA would be suitable, say so, and I will add to this answer.

让您入门:

Minimalistic sysreq.hta:

Minimalistic sysreq.hta:

<html>
    <head>
      <title>System Requirements For XXX</title>
      <hta:application
         id="sysreq"
      ></hta>
      <script type="text/vbscript" src="sysreq.vbs"></script>
      <script type="text/jscript" src="sysreq.js"></script>
    </head>
    <body onload="onload">
      <table id="tblSysReq" border="1" summary="KeepTidyHappy">
       <tr>
        <td id="tdOS">
        </td>
       </tr>
       <tr>
        <td id="tdMSSQL">
        </td>
       </tr>
      </table>
    </body>
</html>

对于正式版,您应该使用HTML编辑器/ide编写漂亮的页面,并仅插入hta元素.有一个过时的向导您可以将HTA特定的(交互式)元素/代码放入HTML中.某些MS安装CD/DVD/ISO包含setup.hta,可用于进一步启发;一些Google搜索会将您指向.hta应用程序,例如系统记录器向导 .未经仔细的单步测试,这些来源都不可信赖.例如:我从 the官方文档,直到我破坏了讨厌的<meta http-equiv="x-ua-compatible" content="ie=9">,它才能在Windows 7上运行.

For the production version you should write a nice page using your HTML editor/ide and just insert the hta element. There is a rather dated wizard that may help you to put HTA specific (interactive) elements/code into your HTML. Some MS install CD/DVD/ISO contain a setup.hta that you may use for further inspiration; some googleing will point you to .hta apps like System Documenter Wizard. None of these sources are to be trusted without carefull single step testing; e.g.: I started my .hta from the official docs and couldn't get it to run on Windows 7 until I zapped the nasty <meta http-equiv="x-ua-compatible" content="ie=9">.

尽管您可能会将脚本内联包含在.hta中,但为了进行开发,最好通过script标记的src属性包含代码.在sysreq.vbs中:

While you probably will include your script inline into the .hta, for developing it's better to include code via the src attribute of the script tag. In sysreq.vbs:

Sub onload()
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colSettings = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
    For Each objOperatingSystem in colSettings
        ' Wscript.Echo "OS Name: " & objOperatingSystem.Caption
        document.getElementById("tdOS").innerText = "OS Name: " & objOperatingSystem.Caption
    Next
    If False Then
       Dim WSHShell : Set WSHShell = CreateObject("WScript.Shell")
      On error resume next
       ' test = wshshell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names")
       test = wshshell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL\SQLEXPRESS")
       If 0 <> Err.Number Then
          ' msgbox "SQL Server not found"
          MsgBox Err.Description
          test = "SQL Server <b>not</b> found"
       Else
          ' msgbox "SQL Server found"
          test = "<i>SQL Server found</i>"
       End If
       document.body.all("tdMSSQL").innerHTML = test
    Else
       JsHelper
    End If
End Sub

我试图遵循您发布的代码;必要的更改是使用document.getElementById()document.body.all()通过写入" HTML元素的innerText/HTML来替换WScript.Echo输出.

I tried to follow the code you published; the necessary changes are to replace the WScript.Echo output by 'writing' to the HTML elements' innerText/HTML by using either document.getElementById() or document.body.all().

要获取收集信息的想法/示例代码,请查看诸如

To get ideas/sample code for the gathering of information, look at tools like Scriptomatic. As you mentioned JScript, I throw in sysreq.js:

function JsHelper() {
    var WSHShell = new ActiveXObject("WScript.Shell")
    try {
      var test = WSHShell.RegRead("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SQL Server\\Instance Names\\SQL\\SQLEXPRESS");
      document.all.tdMSSQL.innerHTML = "<i>SQL Server found</i>";
    }
    catch(e) {
      alert(e);
      document.all.tdMSSQL.innerHTML = "SQL Server <b>not</b> found";
    }
}

让您比较处理相同问题的JScript和VBScript代码.

to let you compare JScript and VBScript code dealing with the same problem.

这值得什么-使用非特权用户帐户在Windows XP和7上对此进行了测试;希望您的里程不会有所不同.

For what this is worth - I tested this on Windows XP and 7 using a non-privileged user account; I hope your mileage may not vary.

WRT chloe的问题是否可以在同一个hta中放置两种不同的脚本语言?":在.HTA(以及.WSF或.WSC)中,您可以混合所有(已安装)ActiveScript语言(VBScript,JScript,Perlscript,通过内联或通过src属性使用script标签,可以使用Pythonscript,Rubyscript等).这对学习很有用,但通常不适合生产代码.

WRT chloe's question "is it possible to put two different scripting languages in the same hta?": In .HTAs (and .WSFs or .WSCs) you can mix all (installed) ActiveScript languages (VBScript, JScript, Perlscript, Pythonscript, Rubyscript, ...) by using the script tag either inline or via the src attribute. This is great for learning, but in general not appropriate for production code.

这篇关于如何从网站执行vbscript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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