HTA中的VBS用于提取系统信息

时间:2015-02-26 03:33:35

标签: vbscript hta

如何将这些字段拉入HTA中每个字段的文本框中。我只需要将这些信息拉到一个文本框中,以显示在我的HTA上以及其他信息

Sub getinfo
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly       = &h20

On Error Resume Next
If WScript.Arguments.UnNamed.Count = 1 Then
strComputer = WScript.Arguments.UnNamed(0)
Else
    strComputer = "."
End If

Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" )
Set colInstances = objWMIService.ExecQuery( "SELECT * FROM Win32_ComputerSystem", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly )

For Each objInstance In colInstances
 WScript.Echo "Domain                      : " & objInstance.Domain
 WScript.Echo "Manufacturer                : " & objInstance.Manufacturer
 WScript.Echo "Model                       : " & objInstance.Model
 WScript.Echo "UserName                    : " & objInstance.UserName

    Next

   end sub

3 个答案:

答案 0 :(得分:1)

附加到textarea的值。 最小样本:

<!DOCTYPE HTML>
<html>
 <head>
  <title>Title</title>
  <hta:application id = "id"></hta>
  <script language = "VBScript" type = "text/vbscript">
'<![CDATA[

Option Explicit

Sub Window_OnLoad()
  Dim taSysInfo : Set taSysInfo = document.GetElementById("taSysInfo")
  Dim i
  For i = 1 to 5
      taSysInfo.value = taSysInfo.value & "line " & i & vbCrLf
  Next
End Sub

']]>
  </script>
 </head>
 <body>
  <form>
   <textarea cols="80" id="taSysInfo" rows="20"></textarea>
  </form>
 </body>
</html>

答案 1 :(得分:1)

你可以试试这个HTA:

<HTA:APPLICATION
  BORDERSTYLE = ""
  CAPTION="yes"
  CONTEXTMENU = "yes"
  INNERBORDER = "no"
  MAXIMIZEBUTTON = "no"
  MINIMIZEBUTTON = "no"
  NAVIGABLE = "Yes"
  SCROLL = "No"
  SCROLLFLAT = "Yes"
  SELECTION="Yes"
  SYSMENU="yes"
  SHOWINTASKBAR="yes"
  SINGLEINSTANCE="yes"
  VERSION = "1.0"
  BORDER="thin"
  >
 <script language="VBScript"> 
 Dim intRamAmt, strCompName, strUserName, strModel
 Dim strCPUSpeed, strManufacturer, strAssetTag
 Set WSHShell = CreateObject("WScript.Shell")
 strComputer = "." 

 Sub Popup(Msg,Wait,Title)
 Set fso = CreateObject("Scripting.FileSystemObject")
 Set ws  = CreateObject("WScript.Shell")
 Dim tempFolder : Set tempFolder = fso.GetSpecialFolder(2)
 Dim tempName : tempName = "Popup.vbs"
  Set objOutputFile = fso.CreateTextFile(tempFolder&"\"&tempName, True)
  objOutputFile.Writeline "Set WshShell = CreateObject(""WScript.Shell"")"
  objOutputFile.WriteLine "BtnCode = WshShell.Popup("&qq(Msg)&","&qq(wait)&","&qq(Title)&",48)"
  objOutputFile.Close
  ws.Run tempFolder&"\"&tempName
End Sub

Function qq(strIn) 
    qq = Chr(34) & strIn & Chr(34)
End Function

 Sub Window_Onload
  window.resizeTo 1,1
  Call Popup("Please be patient until loading all informations and the form will be resized !",30,"Please be patient until loading all informations and the form will be resized !")
 '##### Get Screen Resolution
  Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
  Set colItems = objWMIService.ExecQuery( _
      "SELECT * FROM Win32_DisplayConfiguration",,48) 
  For Each objItem in colItems 
     intHorizontal = objItem.PelsWidth
     intVertical = objItem.PelsHeight
  Next
 '###### Get UserName, ComputerName, ComputerModel, & RAM
  Set colItems = objWMIService.ExecQuery( _
       "SELECT * FROM Win32_ComputerSystem",,48) 
  For Each objItem In colItems
   strCompName = objItem.Name
   strUserName = objItem.UserName
   strModel = objItem.Model
   intRAMamt = Int(objItem.TotalPhysicalMemory / 1048576) & "MB"
  Next
 '####### Get CPU Information
  Set colItems = objWMIService.ExecQuery( _
       "SELECT * FROM Win32_Processor",,48)
  For Each ObjItem In ColItems
   strCPUSpeed = objItem.CurrentClockSpeed & "MHz"
  Next
 '####### Get Manufacturer & Serial Number
  Set objSysCol = objWMIService.ExecQuery ( _
    "Select * from Win32_BIOS",,48)
  For Each objSys In ObjSysCol
   strManufacturer = Objsys.Manufacturer
   strAssetTag = ObjSys.SerialNumber
  Next
 '####### Get SP Level & OS
  Set objSysCol = objWMIService.ExecQuery ( _
    "Select * from Win32_OperatingSystem")
  For each m In ObjSysCol
   strOS = m.caption
   strPatchLevelMajor = m.ServicePackMajorVersion
   strPatchLevelMinor = m.ServicePackMinorVersion
  Next
  intSPLevel = strPatchLevelMajor & "." & strPatchLevelMinor
  strOS = strOS & " SP " & intSPLevel
 '####### Get list of USB devices
  Set colDevices = objWMIService.ExecQuery _
      ("Select * From Win32_USBControllerDevice")
  For Each objDevice in colDevices
      strDeviceName = objDevice.Dependent
      strQuotes = Chr(34)
      strDeviceName = Replace(strDeviceName, strQuotes, "")
      arrDeviceNames = Split(strDeviceName, "=")
      strDeviceName = arrDeviceNames(1)
     Set colUSBDevices = objWMIService.ExecQuery _
         ("Select * From Win32_PnPEntity Where DeviceID = '" & strDeviceName & "'")
      For Each objUSBDevice in colUSBDevices
       Set objOption = Document.createElement("OPTION")
    objOption.Text = objUSBDevice.Name
    objOption.Value = objUSBDevice.Name
    USBDevices.Add(objOption)
      Next    
  Next
 '###### Get last configured NIC w/ IP address
  Set IPConfigSet = objWMIService.ExecQuery _
   ("Select * from Win32_NetworkAdapterConfiguration" _
  & " where IPEnabled=TRUE")
  For Each IPConfig in IPConfigSet
   If Not IsNull(IPConfig.IPAddress) Then 
    For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
     strMacAddr = IpConfig.MACaddress(i)
     strIPAddr = IpConfig.IPAddress(i)
     strNetworkCard = Mid(Ipconfig.Caption(i),12,Len(Ipconfig.Caption(i))-11)
    Next
    If i > 1 Then strIPAddr = strIPaddr & " ( > than 1 IP - check card)"
   End If
   Exit For
  Next 
 '###### Get complete list of Network Cards
 Set colItems = objWMIService.ExecQuery( _
     "SELECT * FROM Win32_NetworkAdapter",,48) 
  For Each objItem in colItems 
  Set objOption = Document.createElement("OPTION")
  objOption.Text = Mid(ObjItem.Caption,12, Len(ObjItem.Caption)-11)
  objOption.Value = Mid(ObjItem.Caption,12, Len(ObjItem.Caption)-11)
  NetDevices.Add(objOption)
 Next
 '###### Get list of Drives
 Set colItems = objWMIService.ExecQuery( _
     "SELECT * FROM Win32_LogicalDisk",,48) 
 For Each objItem in colItems 
  If objItem.Name <> "A:" Then
  Set objOption = Document.createElement("OPTION")
  objOption.Text = objItem.Name & "-Total:" & int(objItem.Size / 107526550)*.1 & "GB" & "-Free Space:" & int(objItem.FreeSpace / 107526550)*.1 & "GB"
  DiskDevices.Add(objOption)
  End IF
 Next
  frmCompName.InnerHTML = strCompName
  frmstrUserName.InnerHTML = strUserName
  frmstrManufacturer.InnerHTML = strManufacturer
  frmstrModel.InnerHTML = strModel
  frmstrAssetTag.InnerHTML = strAssetTag
  frmstrCPUSpeed.InnerHTML = strCPUSpeed
  frmintRAMamt.InnerHTML = intRAMamt
  frmstrOS.InnerHTML = strOS
  frmstrMacAddr.InnerHTML = strMacAddr
  frmstrIPAddr.InnerHTML = strIPAddr
  frmstrNetworkCard.InnerHTML = strNetworkCard

  window.resizeTo 640,300
  intLeft = (intHorizontal - 640) / 2
  intTop = (intVertical - 300) / 2
  window.moveTo intLeft, intTop
 End Sub
 </script>
 <html>
 <head>
 <title>Computer Information</title>
 <style type="text/css">
  @import "all.css"; /* just some basic formatting, no layout stuff */
   body {
   background-color:black;
   margin:0px 0px 0px 0px;
   }
  table {
   border-width: 0px 0px 0px 0px;
   margin:0px 0px 0px 0px;
   padding:0px 0px 5px 5px;
   border-collapse: collapse;
   font-family: arial, Helvetica, sans-serif; 
   font-size: 75%;
   }
  .tblborderline {
   border-bottom: 2px solid white;
   border-top-width: 5px;
   }
  th {
   background-color: black;
   color: white;
   text-align: right;
   vertical-align: bottom;
   font-weight: normal;
   border-collapse: collapse;
   }
  td {
   background-color: black;
   color: yellow;
   text-align: left;
   vertical-align: bottom;
   font-weight: bold;
   border-collapse: collapse;
   }
 </style>
 </head>
 <body>
 <table>
  <tr>
   <th>Computer Name:</th>
   <td><span id=frmCompName></span></td>
  </tr>
  <tr>
      <th>User Name:</th>
      <td><span id=frmstrUserName></span></td>
    </tr>
     <tr>
      <th class="tblborderline">OS:</th>
      <td class="tblborderline"><span id=frmstrOS></span></td>
    </tr>
     <tr>
   <th>Manufacturer:</th>
      <td><span id=frmstrManufacturer></span></td>
    </tr>
     <tr>
   <th>Model:</th>
      <td><span id=frmstrModel></span></td>
    </tr>
  <tr>
   <th class="tblborderline">Asset Tag:</th>
      <td class="tblborderline"><span id=frmstrAssetTag></span></td>
    </tr>
  <tr>
     <th>CPU Speed:</th>
     <td><span id=frmstrCPUSpeed></span></td>
  </tr>
  <tr>
     <th>Memory:</th>
     <td><span id=frmintRAMamt></span></td>
    </tr>
  <tr>
     <th>NIC:</th>
     <td><span id=frmstrNetworkCard></span></td>
    </tr>
  <tr>
     <th>IP:</th>
     <td><span id=frmstrIPAddr></span></td>
    </tr>
  <tr>
     <th class="tblborderline">MAC:</th>
     <td class="tblborderline"><span id=frmstrMacAddr></span></td>
    </tr>
  <tr>
     <th>DISK Devices:</h>
     <td><select name="DiskDevices"></select></td>
  </tr>
  <tr>
   <th>NET Devices:</th>
     <td><select name="NetDevices"></select></td>
  </tr>
  <tr>
   <th>USB Devices:</th>
     <td><select name="USBDevices"></select></td>
  </tr>
 </table>
 </body>
 </html>

答案 2 :(得分:0)

我将WScript.Echo行翻译为textarea.write行:

  1. 以HTML格式创建TEXTAREA
  2. 为该TEXTAREA
  3. 声明JavaScript write()函数
  4. 在VBScript中调用write()函数
  5. 通过在BODY元素的末尾声明所有内容,我们知道大部分DOM已准备好并且可以由脚本使用(节省我们编写Window_OnLoad处理程序)
  6. 实际上,你是代码,应用最少的HTA装饰:

    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="x-ua-compatible" content="ie=9" />
    </head>
    <body>
    <textarea cols="80" id="taSysInfo" rows="20">
    </textarea>
    <script type="text/javascript">
    taSysInfo.write = function(txt) { taSysInfo.value += txt + "\r\n"; }
    </script>
    <script type="text/vbscript">
    Const wbemFlagReturnImmediately = &h10
    Const wbemFlagForwardOnly       = &h20
    strComputer = "."
    Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" )
    Set colInstances = objWMIService.ExecQuery( "SELECT * FROM Win32_ComputerSystem", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly )
    For Each objInstance In colInstances
        taSysInfo.write "Domain                      : " & objInstance.Domain
        taSysInfo.write "Manufacturer                : " & objInstance.Manufacturer
        taSysInfo.write "Model                       : " & objInstance.Model
        taSysInfo.write "UserName                    : " & objInstance.UserName
    Next
    </script>
    </body>
    </html>