Re: Getting Computer Name
Re: Getting Computer Name
- Subject: Re: Getting Computer Name
- From: John Joyce <email@hidden>
- Date: Sun, 20 Jun 2010 13:01:47 -0500
On Jun 20, 2010, at 8:46 AM, Steve Steinitz wrote:
> Hi Paul,
>
> On 20/6/10, Paul Sanders wrote:
>
>>>> Are you #including <CoreServices/CoreServices.h>?
>>
>>> I wasn't. I added it. Were you wondering if it would make a difference?
>>
>> Well, yes. Default return type is int. In fact I'm suprised you
>> didn't get a warning about the function being undefined. My Mac is
>> powered off or I would check. Does adding the #include sort things
>> out?
>
> No, it doesn't seem to make a difference. I might raise a bug report. in the meantime I'm using:
>
> [[NShost currentHost] name];
>
> which apparently can block for a while and doesn't guarantee which host name it will return from among the array of host names. Surprisingly, my development machine has four, including one that Adobe slipped in there.
>
> Thanks again for your help Paul.
>
> Signing off for the night,
>
> Steve
Which name are you trying to acquire ?
The host name is not guaranteed to be the same as the name set in System Preference > Sharing
The "Computer Name" there is where most users will set it, and is the one commonly seen in Finder windows. It can be localized.
This is different from a localhost name. The host name can be very different.
If you want the Computer Name of the computer as set by an admin user in System Preferences, use CSCopyMachineName()
As an example, try this in your app delegate:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
NSLog(@"Computer Name: %@",CSCopyMachineName());
}
Please keep in mind, that this may not be in English.
I myself found this to be difficult to locate with simple searches both in the developer docs and on the web, though less than 5 minutes of googling did turn it up.
Hope that helps,
John Joyce_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden