1

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.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Rich Michaels
  • 1,663
  • 2
  • 12
  • 18

2 Answers2

1

There is a way but it requires the admin password

do shell script "defaults read /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName" with administrator privileges
vadian
  • 274,689
  • 30
  • 353
  • 361
  • thank you. Knowing the location helps. I now need to figure out how to silently read it without having admin rights. Even inputting the plist file as text file stream and parsing the text string, causes a user prompt to grant access to the file. Not the end of the world, but less desirable IMO. – Rich Michaels Aug 20 '19 at 21:25
1

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.)