Mac OS X:从目录服务获取当前用户的当前用户名和主目录

编程入门 行业动态 更新时间:2024-10-11 21:24:46
本文介绍了Mac OS X:从目录服务获取当前用户的当前用户名和主目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的应用程序是用Objective-C编写的.如何通过目录服务获取当前登录用户的用户名和主目录?

My app is written in Objective-C. How can I get the user name and home directory of the currently logged in user through directory services?

详细信息: 我的Cocoa应用使用getenv("USER")和getenv("HOME")获取当前的用户名和主目录.显然,如果用户通过目录服务登录,这将无法正常工作.我正在执行chdir($ HOME),然后运行此命令: 登录-fp $ USER 并且它拒绝了它,因为我认为登录通过目录服务来对用户进行身份验证,并且该用户在该系统中的用户名可能与$ USER的值不同.同样,他可能在目录服务中指定的主目录与$ HOME不同.

Detail: My Cocoa app gets the current username and home directory with getenv("USER"), getenv("HOME"). Apparently this doesn't work right if the user is logged in through directory services. I am doing a chdir($HOME) and then running this command: login -fp $USER and it rejects it because, I think, login goes through the directory service to authenticate the user, and his username in that system may not be the same as the value of $USER. Likewise, he may have a home directory specified in directory services that is different than $HOME.

推荐答案

尝试NSUserName()和NSHomeDirectory().

更多推荐

Mac OS X:从目录服务获取当前用户的当前用户名和主目录

本文发布于:2023-11-28 12:04:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1642329.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:主目录   用户名   目录   用户   Mac

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!