Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > How to get machine name?

How to get machine name?
Thread Tools
kman42
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
May 26, 2003, 02:22 PM
 
I know I can use NSFullUserName() to get the users name. Is there an analogous way to get the name of the computer?

kman
     
Angus_D
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
May 26, 2003, 05:53 PM
 
SCDynamicStoreCopyComputerName in SystemConfiguration.framework
     
kman42  (op)
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
May 26, 2003, 06:28 PM
 
Originally posted by Angus_D:
SCDynamicStoreCopyComputerName in SystemConfiguration.framework
Thanks. How do I go about actually getting that information?

kman
     
Angus_D
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
May 27, 2003, 10:13 AM
 
Create a dynamic store, and copy it out using that function. See the headers and documentation.
     
kman42  (op)
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
May 27, 2003, 01:37 PM
 
Sorry. I don't know what a dynamic store is and I can't find those frameworks anywhere. Could you explain a bit more for a newbie? I haven't ventured much out of Foundation and Appkit.

kman
     
seb2
Grizzled Veteran
Join Date: Feb 2001
Location: Germany
Status: Offline
Reply With Quote
May 27, 2003, 02:55 PM
 
Don't worry about the store. Just pass "NULL", it'll create a temporary session for you:

NSString *hostname = (NSString *)SCDynamicStoreCopyComputerName(NULL, NULL);

does the trick.
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
May 27, 2003, 03:11 PM
 
Just remember that 1) You'll have to link in the SystemConfiguration framework, 2) You'll have to include <SystemConfiguration/SystemConfiguration.h>, and 3) You'll have to release the string obtained from that function.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
kman42  (op)
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
May 27, 2003, 06:33 PM
 
Originally posted by Chuckit:
Just remember that 1) You'll have to link in the SystemConfiguration framework, 2) You'll have to include <SystemConfiguration/SystemConfiguration.h>, and 3) You'll have to release the string obtained from that function.
Well, I think I did #2 okay, but I'm not sure how to do #1. For #2, I just did:
#import <SystemConfiguration/SystemConfiguration.h>

Here's the error I'm getting now during the build:

ld: ~/Documents/Programming/F@HMonitor/build/[email protected]/[email protected]/Objects-normal/ppc/FMController.o illegal reference to symbol: _SCDynamicStoreCopyComputerName defined in indirectly referenced dynamic library /System/Library/Frameworks/SystemConfiguration.framework/Versions/A/SystemConfiguration
     
kman42  (op)
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
May 27, 2003, 06:36 PM
 
Nevermind. I found the 'Add Framework...' menu item in PB. Now it works great! Thanks for all the help.

kman
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 05:16 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,