VBScript自定义文本框

时间:2015-04-07 13:15:04

标签: vbscript

我目前有一个脚本,它接受一个PC名称,然后输出IP地址,然后输出另一个带有完全限定域名的文本框。我一直在使用InputBox而不是Msgbox,因为我需要能够将结果复制到剪贴板。

我的问题是:有没有办法在同一个文本框中输出IP和FQDN,并且有一个“复制到剪贴板”'每个旁边的按钮?

以下是我目前使用的内容:

Sub Ping

Set objShell = CreateObject("WScript.Shell")
    Dim tmp

    Const ForReading = 1
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Message = "Enter the Computer Name you would like to convert to an IP address."
    Host_Names=InputBox(message)

    wmiQuery = "Select * From Win32_PingStatus Where " & _
    "Address = '" & Host_Names & "'"

    Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
    Set objPing = objWMIService.ExecQuery(wmiQuery)

        For Each objStatus in objPing
            If IsNull(objStatus.StatusCode) Or objStatus.Statuscode<>0 Then
                    Msgbox Host_Names & " is Unreachable!"
            Exit Sub
            Else
            tmp = InputBox("The IP Address is:",,objStatus.ProtocolAddress)
            tmp = objStatus.ProtocolAddress
            End If
    Next

    strIP = tmp

    if strIP = "" then 
        Exit Sub
    end if

    Set objScriptExec = objShell.Exec("ping.exe -n 1 -a " & strIP)
    strPingResult = objScriptExec.StdOut.ReadAll
    Set objStdOut = objScriptExec.StdOut

    strNoPing = "Request timed out."

    arrayPingResult = split(strPingResult, vbcrlf)

    strCheck = strComp(arrayPingResult(3), strNoPing, 1)

    if strCheck = 1 then
        Msgbox "PC not on the network. Quitting Program"
        Exit Sub
    else
        arrayPCLine = split(arrayPingResult(1), " ")
        tmp = InputBox("The fully qualified name is:",,arrayPCLine(1))

    end if
End Sub

感谢您提供任何帮助。

3 个答案:

答案 0 :(得分:3)

VBScript的“自然”GUI是.HTA。如:

<html>
 <head>
  <title>ClipBoard Demo</title>
  <hta:application
     id="demo"
  ></hta>
  <script type="text/vbscript">

Option Explicit

Sub Window_OnLoad()
  document.GetElementById("teIP").value = "1.2.3.4"
  document.GetElementById("teNA").value = "HAL"
End Sub

Sub clpME(sTXT)
' MsgBox document.GetElementById(sTXT).value
  window.clipboardData.setData "text", document.GetElementById(sTXT).value
End Sub

  </script>
 </head>
 <body>
  <form>
   <input type="text" id="teIP">
   <input type="button" onclick='clpME "teIP"' value="clp">
   <br />
   <input type="text" id="teNA">
   <input type="button" onclick='clpME "teNA"' value="clp">
  </form>
 </body>
</html>

(更详细examplestart here

答案 1 :(得分:2)

我不会假装这很漂亮,但如果您正在寻找一个快速而肮脏的解决方案,您可以劫持内置按钮。我之前见过这个:

Dim msgboxResponse
msgboxResponse = MsgBox("Press: " & vbCrLf _
    & "Yes to copy IP address" & vbCrLf _
    & "No to copy FQDN" & vbCrLf _
    & "Cancel to copy nothing", vbYesNoCancel)

Select Case msgboxResponse
Case vbYes: 'Code to copy IP to clipboard
Case vbNo: 'Code to copy FQDN
Case vbCancel: 'do nothing

看见UX天堂:

enter image description here     结束选择

答案 2 :(得分:0)

虽然不明显,但只需按 Ctrl-Ins 即可将任何msgbox的内容复制到剪贴板,但标题和按钮也包含在内。

您可以使用clip.exe命令行实用程序将数据放在剪贴板中。

With WScript.CreateObject("WScript.Shell")
    .Environment("PROCESS")("_toClip") = "Here, concatenate the variables to place in clipboard"
    .Run "cmd /v /q /c ""echo(!_toClip!|clip""", 0, True
    .Environment("PROCESS").Remove "_toClip"
End With

当然,不是显示两个输入框,而是连接数据,然后只显示一个包含所有必需信息的输入框。