使用 VBA 或 AppleScript 在 Mac OS X 上获取 NetBIOS 名称

Get NetBIOS Name on Mac OS X Using VBA or AppleScript

我有一个 Mac Word VBA 应用程序,我需要读取应用程序所在计算机的 NetBIOS 名称 运行。我可以使用以下代码获取用户名和计算机名,但我无法弄清楚如何读取 NetBIOS 名称。

Sub GetSystemInfo()
    Dim Script As String, UserName As String, ComputerName As String, NetBiosName As String
    Script = "set user to do shell script ""whoami"""
    UserName = VBA.MacScript(Script)
    Script = "computer name of (system info)"
    ComputerName = VBA.MacScript(Script)
End Sub

不幸的是,Mac 上的 VBA 没有直接获取它的方法,所以我正在寻找 Mac 脚本或其他可以集成的编程方法使用 VBA 例程顺利进行。

非常感谢任何帮助。

有办法,但需要管理员密码

do shell script "defaults read /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName" with administrator privileges

AFAICS 这不是管理员权限问题,而是沙盒问题。不确定您是否可以在不使用 AppleScriptTask 和 distributing/installing 一个合适的脚本的情况下解决这个问题 docm/dotm。例如

以下适用于没有管理员权限的用户:

创建一个名为

的AppleScript
getNBName.applescript 

~/Library/Application Scripts/com.microsoft.Word 

包含以下代码

on doit(dummy)
    return (do shell script "defaults read /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName")
end doit

像这样使用VBA:

Sub getNetBIOSName()
Dim theName As String
theName = AppleScriptTask("getNBName.applescript", "doit", "")
Debug.Print theName
End Sub

(注意,您不能使用 VBA Open/Print/Close 将脚本动态写入 com.microsoft.Word 文件夹,然后再调用它,这也可能是因为沙盒。)