Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBScript custom textbox

Tags:

vbscript

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.

like image 965
Walthavian Avatar asked May 01 '26 01:05

Walthavian


2 Answers

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)

like image 67
Ekkehard.Horner Avatar answered May 06 '26 08:05

Ekkehard.Horner


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:

enter image description here End Select

like image 21
Jean-François Corbett Avatar answered May 06 '26 08:05

Jean-François Corbett



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!