Reputation: 33
I currently have a script that takes a PC name and then outputs the IP Address and then another textbox with the Fully Qualified Domain Name. I have been using the InputBox instead of Msgbox as I need to be able to copy the results to the clipboard.
My question is: Is there a way to output both the IP and the FQDN in the same textbox and have a 'Copy to Clipboard' button next to each of those?
Here is what I've been using so far:
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
Thanks for any help you can give me.
Upvotes: 3
Views: 5441
Reputation: 38745
The 'natural' GUI for VBScript is .HTA. As in:
<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>
(More elaborate example, start here)
Upvotes: 3
Reputation: 70923
While not evident, you can copy the content of any msgbox to clipboard just by pressing Ctrl-Ins, but the title and the buttons are also included.
You can just place the data in the clipboard using the clip.exe
command line utility.
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
And, of course, instead of showing the two inputboxes, just concatenate the data and then show only one input box with all the required information.
Upvotes: 0
Reputation: 38500
I'm not going to pretend this is pretty, but if you're looking for a quick and dirty solution, you can hijack the built-in buttons. I have seen this done before:
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
Behold UX heaven:
End Select
Upvotes: 2