我目前有一个脚本,它采用 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
感谢您给我的任何帮助。
最佳答案
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>
(更详细 example 、 start here )
关于VBScript 自定义文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29492556/