Code:
ImportC ""
CFRelease(CFTypeRef.L)
CFStringGetCString(CFStringRef.L, *Buffer, BufferSize, Encoding.L)
CSCopyMachineName()
CSCopyUserName(UseShortName.L)
EndImport
Procedure.S AddNameToInfo(NameRef.L, Description.S)
Shared Info.S
Protected Name.S = Space(100)
If NameRef
If CFStringGetCString(NameRef, @Name, Len(Name), 0)
Info + #CR$ + Description + " = " + Name
EndIf
CFRelease(NameRef)
EndIf
EndProcedure
Define Info.S
AddNameToInfo(CSCopyMachineName(), "Machine name")
AddNameToInfo(CSCopyUserName(#True), "User's short name")
AddNameToInfo(CSCopyUserName(#False), "User's long name")
MessageRequester("System Info", Info)
A much easier way to obtain the computer's name would be the PureBasic
function Hostname() (and therefore even cross-platform):
Code:
InitNetwork()
Debug Hostname()
But it doesn't display the correct name of my iMac because it attaches the
name of my DSL router:
Debug Hostname() wrote:
shardiks-imac.fritz.box
whereas my first API code example displays the correct name
Quote:
Shardiks-iMac
Update: freak clarified that the host name is not necessarily identical to the computer name:
viewtopic.php?f=24&t=46652&start=1