我要求通过VBS获取PC的IP地址,我正在使用以下内容:
strQuery = "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE MACAddress > ''"
Set objWMIService = GetObject( "winmgmts://./root/CIMV2" )
Set colItems = objWMIService.ExecQuery( strQuery, "WQL", 48 )
For Each objItem In colItems
If IsArray( objItem.IPAddress ) Then
If UBound( objItem.IPAddress ) = 0 Then
strIP = "IP Address: " & objItem.IPAddress(0)
Else
strIP = "IP Addresses: " & Join( objItem.IPAddress, "," )
End If
End If
Next
然后我使用下面的地图来映射网络驱动器:
Option Explicit
Dim objNetwork
Dim strDriveLetter, strRemotePath, strUser, strPassword, strProfile
strDriveLetter = "Z:"
strRemotePath = "\\10.121.34.140\c$"
strUser = "user"
strPassword = "Password"
strProfile = "false"
Set objNetwork = WScript.CreateObject("WScript.Network")
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, _
strProfile, strUser, strPassword
我想要做的是获取hostmachine的IP(所以10.121.34.130
)并将八位字节改为.140
并映射到那个。
我该怎么做?
答案 0 :(得分:2)
InStrRev()
和Left()
函数应该就是您所需要的。
' Sample starting address...
strIP = "10.121.34.130"
' Get the index of the last period...
i = InStrRev(strIP, ".")
' Append the new last octet starting there...
strIP = Left(strIP, i) & "140"
或者,作为一个单行:
strIP = Left(strIP, InStrRev(strIP, ".")) & "140"
或者,作为创建完整远程路径的单行:
strIP = "\\" & Left(strIP, InStrRev(strIP, ".")) & "140\c$"