繁体   English   中英

使用 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 并使用您的文档/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 文件夹,这也可能是因为沙盒。)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM