Convert the Unicode full name to ANSI

本文介绍了一个C语言程序,该程序能够通过Windows API从指定域中获取用户的完整名称。它使用了多个头文件,如windows.h、lm.h 和stdio.h,并定义了一个名为GetFullName的函数来实现这一功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

点击标题进入,格式即正常。



#include <windows.h> #include <lm.h> #include <stdio.h> BOOL GetFullName( char *UserName, char *Domain, char *dest ) { WCHAR wszUserName[256]; // Unicode user name WCHAR wszDomain[256]; LPBYTE ComputerName; struct _SERVER_INFO_100 *si100; // Server structure struct _USER_INFO_2 *ui; // User structure // Convert ANSI user name and domain to Unicode MultiByteToWideChar( CP_ACP, 0, UserName, strlen(UserName)+1, wszUserName, sizeof(wszUserName)/sizeof(wszUserName[0]) ); MultiByteTOWideChar( CP_ACP, 0, Domain, strlen(Domain)+1, wszDomain, sizeof(wszDomain)/sizeof(wszDomain[0]) ); // Get the computer name of a DC for the domain. NetGetDCName( NULL, wszDomain, &ComputerName ); // Look up the user on the DC. if( NetUserGetInfo( (LPWSTR) ComputerName, (LPWSTR) &wszUserName, 2, (LPBYTE *) &ui ) ) { printf( "Error getting user information.\n" ); return( FALSE ); } // Convert the Unicode full name to ANSI. WideCharToMultiByte( CP_ACP, 0, ui->usri2_full_name, -1, dest, 256, NULL, NULL ); return (TRUE); }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值