It is currently Mon May 20, 2013 1:39 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Obtain computer name and user name
PostPosted: Thu Jun 16, 2011 8:15 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 814
Location: Germany
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


Top
 Profile  
 
 Post subject: Re: Obtain computer name and user name
PostPosted: Wed Mar 21, 2012 6:16 pm 
Offline
User
User

Joined: Wed Mar 21, 2012 6:10 pm
Posts: 30
I can't access to the post specified upper... any idea why?


Top
 Profile  
 
 Post subject: Re: Obtain computer name and user name
PostPosted: Wed Mar 21, 2012 9:58 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 814
Location: Germany
Golfy wrote:
I can't access to the post specified upper... any idea why?

The thread linked in my first post to freak's explanation was
presumably moved to an area that cannot be accessed anymore
by normal board users because it was originally posted in the
MacOS bugs subforum. All corrected bug reports or falsely
reported errors (as in this case) are moved after some time to
an inaccessible board area... :wink:


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye