创建 VBS,用当前用户的用户名、计算机名和多个 IP 地址创建一个消息框(有线/无线) [英] Create VBS that creates a message box with the current user's - username, computer name, and multiple IP addresses for (wired/wireless)

查看:25
本文介绍了创建 VBS,用当前用户的用户名、计算机名和多个 IP 地址创建一个消息框(有线/无线)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在已经四处寻找了一些,我想出了这个脚本的组合......它几乎满足了我的需求,但是当涉及到 IP 时,它在消息框上看起来并不漂亮地址...目前它们一起显示,没有空间示例(wiredIPwirelessIP).理想情况下,我想要的是让消息框说用户名:用户计算机名称:Computer1有线IP:X.X.X.X无线IP:X.X.X.X

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

任何帮助将不胜感激.

这是我目前所拥有的

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

推荐答案

我认为这会对您有所帮助:

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://docs.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

附言消息框可能提供信息,但不允许用户将信息复制为文本并通过邮件发送给 IT.也许您应该添加一行告诉他们按 Alt + PrtScn 并使用 Ctrl + V 将其粘贴到电子邮件中>

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

这篇关于创建 VBS,用当前用户的用户名、计算机名和多个 IP 地址创建一个消息框(有线/无线)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆