0

I've been looking around for a bit now, and I have come up with this mix of script...it does pretty much what I need but it does not look pretty on the message box when it comes to the IP address...currently they are displayed together with no space example (wiredIPwirelessIP). Ideally what I would like is to have the message box say Username: user Computer Name: Computer1 Wired IP: X.X.X.X Wireless IP: X.X.X.X

Any help would be appreciated.

Here is what I have so far

On Error Resume Next
Dim WSH
Dim strComputerName, FinalIP
Set WSH = WSCript.CreateObject("WScript.Shell") 
Set WshNtwk = WScript.CreateObject("WScript.Network") 
strMsg = ""
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set IPAdapterSet = objWMIService.ExecQuery("Select AdapterType, NetConnectionID, MACAddress from Win32_NetworkAdapter")
For Each IPConfig in IPAdapterSet
Set IPConfigSet = objWMIService.ExecQuery("Select IPEnabled, Description, Caption, IPAddress, MACAddress from Win32_NetworkAdapterConfiguration where IPEnabled='True' AND MACAddress = '" & IPConfig.MACAddress & "'")
For Each IPConf in IPConfigSet
''strMsg = strMsg
If Not IsNull(IPConf.IPAddress) Then
For i = LBound(IPConf.IPAddress) to UBound(IPConf.IPAddress)
If Not ((Instr(IPConf.IPAddress(i), ":") > 0) or (Instr(IPConf.IPAddress(i), "none") > 0)) Then
if i=0 then
strMsg = strMsg & IPConf.IPAddress(i)
else
strMsg = strMsg & ", " & IPConf.IPAddress(i) 
end if
End If
Next
End If
next
Next
''WScript.Echo strMsg
Dim infroStr
infoStr = "Please provide the following information to the IT Technician." & vbCRLF & vbCRLF & _
"               Username :" & vbTab & WshNtwk.UserName & vbCRLF & _
"   Computer Name :" & vbTab & Ucase(WshNtwk.ComputerName) & vbCRLF & _
"        IP Address(es) :" & vbTab & strMsg
'"Domain:" & WshNtwk.UserDomain
' Display the IP address and computer name in user-friendly message box 
MsgBox infoStr, 64, "Some Title"
'"Computer Name:" & vbTab & Ucase(WshNtwk.ComputerName) & vbCrLf & "IP Address:" & vbTab & FinalIP, vbOkOnly , "SCCCMHA PC Information"
On Error Goto 0
WScript.Quit

1 Answers1

1

I think this will help you:

Option Explicit

On Error Resume Next
Dim WSH, WshNtwk, objWMIService, IPAdapterSet, IPConfig, IPConfigSet, IPConf
Dim strMsg, strComputer, infoStr, FinalIP

Set WSH = WSCript.CreateObject("WScript.Shell")
Set WshNtwk = WScript.CreateObject("WScript.Network")
strMsg = ""
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set IPAdapterSet = objWMIService.ExecQuery("Select AdapterTypeID, NetConnectionID, MACAddress from Win32_NetworkAdapter")

' values for AdapterTypeID: https://learn.microsoft.com/en-us/windows/desktop/cimwin32prov/win32-networkadapter
For Each IPConfig in IPAdapterSet
    Set IPConfigSet = objWMIService.ExecQuery("Select IPEnabled, Description, Caption, IPAddress, MACAddress from Win32_NetworkAdapterConfiguration where IPEnabled='True' AND MACAddress = '" & IPConfig.MACAddress & "'")
    For Each IPConf in IPConfigSet
        If Not IsNull(IPConf.IPAddress) Then
            If Instr(1, IPConfig.NetConnectionID, "Wireless", vbTextCompare) > 0 Then
                strMsg = strMsg & "- Wireless IP: " & vbTab
            Else
                strMsg = strMsg & "- Wired IP:    " & vbTab
            End If

            strMsg = strMsg & Join(IPConf.IPAddress, ", ") & vbCrLf
            strMsg = strMsg & "- MAC Address: " & vbTab & IPConfig.MACAddress & vbCrLf & vbCrLf
        End If
    Next
Next

''WScript.Echo strMsg
infoStr = "Please provide the following information to the IT Technician." & vbCrLf & vbCrLf & _
"Username :" & vbTab & WshNtwk.UserName & vbCrLf & _
"Computer Name :" & vbTab & Ucase(WshNtwk.ComputerName) & vbCrLf & _
"IP Addresses:" & vbCrLf & strMsg
'"Domain:" & WshNtwk.UserDomain
' Display the IP address and computer name in user-friendly message box
MsgBox infoStr, 64, "Some Title"
'"Computer Name:" & vbTab & Ucase(WshNtwk.ComputerName) & vbCrLf & "IP Address:" & vbTab & FinalIP, vbOkOnly , "SCCCMHA PC Information"
On Error Goto 0

'cleanup
Set IPConf = Nothing
Set IPConfig = Nothing
Set objWMIService = Nothing
Set IPAdapterSet = Nothing
Set WSH = Nothing
Set WshNtwk = Nothing

WScript.Quit

P.s. The messagebox may be informative, but does not allow users to copy the info as text and send it to IT in a mail for instance. Maybe you should add a line telling them to press Alt + PrtScn and paste that in an email with Ctrl + V

Theo
  • 57,719
  • 8
  • 24
  • 41
  • Thank you so much. This is exactly what I was looking for! I appreciate your time and help. Also appreciate your note about informing the user to print screen and email. Thank you again! – ThrowingFitz Aug 27 '18 at 14:14
  • Actually I just tested on a PC with wireless but the message states Wired IP both for the physical and wireless...any suggestions? Thank you! – ThrowingFitz Aug 27 '18 at 14:20
  • ..I'm on wired now so I cannot check. What does `IPConfig.AdapterTypeID` tell us? Can you do a `WScript.Echo IPConfig.AdapterTypeID` there? – Theo Aug 27 '18 at 14:24
  • I think I've found out why. The `AdapterTypeID` returns the type for the network medium **in use**. I edited my answer now to use a different property `NetConnectionID`. That property returns the name of the network connection as it appears in the Network Connections Control Panel program. By checking if the term `wireless` is somewhere in that string we should do a better job here. – Theo Aug 27 '18 at 14:56