📅  最后修改于: 2023-12-03 15:29:01.801000             🧑  作者: Mango
vbox
地址 - VBA默认主机 vbox
地址 - VBA,是一个用于获取 VirtualBox 中已经定义的虚拟机地址的 VBA 函数。
Alt + F11
进入 VBA 编辑器。vbox.bas
文件中的代码。=VBOX()
即可获取 VirtualBox 默认主机地址。vbox.bas
中 VirtualBoxPath
的值。Function VBOX() As String
Dim VirtualBoxPath As String
VirtualBoxPath = "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe"
' 获取默认主机名称
Dim HostName As String
HostName = ""
Dim HostCommand As String
HostCommand = VirtualBoxPath & " list hosts"
Shell (HostCommand), vbHide
Dim HostInfo As String
HostInfo = ""
Open "C:\WINDOWS\system32\drivers\etc\hosts" For Input As #1
Do While Not EOF(1)
Line Input #1, HostInfo
If InStr(1, HostInfo, "#") = 0 Then
If InStr(1, HostInfo, "127.0.0.1") > 0 Then
HostName = Right(HostInfo, Len(HostInfo) - InStr(1, HostInfo, " "))
End If
End If
Loop
Close #1
' 获取默认主机地址
Dim DefaultVMCommand As String
DefaultVMCommand = VirtualBoxPath & " --nologo guestproperty get " & HostName & " /VirtualBox/GuestInfo/Net/0/V4/IP"
Dim DefaultVMInfo As String, DefaultVMAddr As String
DefaultVMInfo = ""
DefaultVMAddr = ""
Open "C:\WINDOWS\system32\drivers\etc\hosts" For Input As #1
Do While Not EOF(1)
Line Input #1, DefaultVMInfo
If InStr(1, DefaultVMInfo, "=") > 0 Then
DefaultVMAddr = Right(DefaultVMInfo, Len(DefaultVMInfo) - InStrRev(DefaultVMInfo, "="))
Exit Do
End If
Loop
Close #1
VBOX = DefaultVMAddr
End Function