在c ++中以编程方式找到用户名? [英] Programmatically find username in c++?

查看:179
本文介绍了在c ++中以编程方式找到用户名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个小应用程序,使轻松一些任务在MS Word。应用程序必须在Word中导入为宏,这意味着必须存储在用户下的一些模板文件夹中。因此,我不知道如何知道用户名是什么,以及 Windows版本,因为我的用户名和文件夹位置与某人不同其他。
有没有一些bat代码,或者c ++中的一些函数可以很容易地把这两个信息存储在变量中,我可以很容易地在安装应用程序时使用它?

I'm creating little application which make easy some task in MS Word. Application have to be imported in Word as macro, that's mean that have to be stored in some template folder which is under user. So I wan't to find out how to know what is the name of user, and what is version of windows, cause my username and folder location is not same as someone else. Is there any little bat code, or some function in c++ that can easy just take those two information and store it in variable, that I can easy use it when installing application?

OS:win7,vista,xp

OS: win7, vista,xp

推荐答案

要获取用户名, http://msdn.microsoft.com/en-us/library/windows/desktop/ms724432%28v=vs.85%29.aspx> GetUserName()函数。

To get the user name you use the GetUserName() function.

但是,这不是确定当前用户的文件夹位置的最佳方法。对于使用类似 SHGetSpecialFolderPath() SHGetFolderPath(),它可以特殊文件夹的路径(例如用户的应用程序文件夹,其桌面等)

However, this is not the best way to determine the current user's folder locations. For that use something like SHGetSpecialFolderPath() or SHGetFolderPath() instead which can give the path of a special folder (such as the user's application folder, their desktop etc)

这篇关于在c ++中以编程方式找到用户名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆