vbamacosms-wordapplescriptnetbios

Get NetBIOS Name on Mac OS X Using VBA or AppleScript


I have a Mac Word VBA application where I need to read the NetBIOS name of the computer the application is running on. I can pickup the User Name and Computer Name with the following code, but I have not been able to figure out how to read the NetBIOS name.

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

Unfortunately, VBA on a Mac does not have a method to get at it directly, so I am looking for either a Mac Script or other programmatic method that would integrate smoothly with the VBA routine.

Any help is much appreciated.


Solution

  • AFAICS it is not an admin rights issue but a sandboxing one. Not sure that you can solve that without using AppleScriptTask and distributing/installing a suitable script with your docm/dotm. e.g.

    The following works here for a user without admin rights:

    Create an AppleScript called

    getNBName.applescript 
    

    in

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

    containing the following code

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

    Use VBA like this:

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

    (NB, you cannot use VBA Open/Print/Close to write the script to the com.microsoft.Word folder dynamically before invoking it, possibly also because of sandboxing.)