如何根据登陆win2000server的用户名,获取登陆的机器名

wangj2001 2002-08-29 05:46:07
如题
...全文
62 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
WadeHan 2002-08-30
  • 打赏
  • 举报
回复
//计算机名
TCHAR szTemp[MAX_PATH];
DWORD len=sizeof(szTemp);
GetComputerName(szTemp,&len);
CString sComputerName;
sComputerName.Format("%s",szTemp);
WadeHan 2002-08-30
  • 打赏
  • 举报
回复

Platform SDK: Windows System Information
GetComputerNameEx
The GetComputerNameEx function retrieves a NetBIOS or DNS name associated with the local computer. The names are established at system startup, when the system reads them from the registry.

GetComputerNameEx can retrieve the NetBIOS name retrieved by the GetComputerName function. In addition, GetComputerNameEx can retrieve fully qualified, host, and domain DNS names.

If the local computer is a node in a cluster, GetComputerNameEx can return either the name of the cluster or the name of the local computer.

BOOL GetComputerNameEx(
COMPUTER_NAME_FORMAT NameType, // name type
LPTSTR lpBuffer, // name buffer
LPDWORD lpnSize // size of name buffer
);
Parameters
NameType
[in] A value from the COMPUTER_NAME_FORMAT enumeration type that specifies the type of name to retrieve.
This parameter can be one of the following values from the COMPUTER_NAME_FORMAT enumeration type that specifies the type of name to retrieve. Value Description
ComputerNameNetBIOS The NetBIOS name of the local computer. If the local computer is a node in a cluster, lpBuffer receives the NetBIOS name of the cluster.
ComputerNameDnsHostname The DNS host name of the local computer. If the local computer is a node in a cluster, lpBuffer receives the DNS host name of the cluster.
ComputerNameDnsDomain The name of the DNS domain assigned to the local computer. If the local computer is a node in a cluster, lpBuffer receives the DNS domain name of the cluster.
ComputerNameDnsFullyQualified The fully qualified DNS name that uniquely identifies the local computer. This name is a combination of the DNS host name and the DNS domain name, using the form HostName.DomainName. If the local computer is a node in a cluster, lpBuffer receives the fully qualified DNS name of the cluster.
ComputerNamePhysicalNetBIOS The NetBIOS name of the local computer. If the local computer is a node in a cluster, lpBuffer receives the NetBIOS name of the local computer, not the name of the cluster.
ComputerNamePhysicalDnsHostname The DNS host name of the local computer. If the local computer is a node in a cluster, lpBuffer receives the DNS host name of the local computer, not the name of the cluster.
ComputerNamePhysicalDnsDomain The name of the DNS domain assigned to the local computer. If the local computer is a node in a cluster, lpBuffer receives the DNS domain name of the local computer, not the name of the cluster.
ComputerNamePhysicalDnsFullyQualified The fully qualified DNS name that uniquely identifies the computer. If the local computer is a node in a cluster, lpBuffer receives the fully qualified DNS name of the local computer, not the name of the cluster.
The fully qualified DNS name is a combination of the DNS host name and the DNS domain name, using the form HostName.DomainName.




lpBuffer
[out] Pointer to a buffer that receives a null-terminated string containing the computer name.
The length of the name may be greater than MAX_COMPUTERNAME_LENGTH characters because DNS allows longer names.

lpnSize
[in/out] On input, specifies the size, in TCHARs, of the buffer. On output, receives the number of TCHARs copied to the destination buffer, including the terminating null character.
If the buffer is too small, the function fails and GetLastError returns ERROR_MORE_DATA.

Return Value
If the function succeeds, the return value is a nonzero value.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks
The GetComputerNameEx function retrieves the NetBIOS or DNS names established at system startup. Name changes made by the SetComputerName or SetComputerNameEx functions do not take effect until the user restarts the computer.

When a computer is a node in a cluster, an application can get a cluster name instead of the node name by using the appropriate value for NameType. This lets a cluster-unaware application see a consistent node name regardless of which cluster node is hosting the application. For this to happen, the following must be true:

the application is running as a cluster resource with a dependency on a cluster Network Name [sic] resource.
the resource DLL managing the application calls ResUtilGetEnvironmentWithNetName and passes the resulting environment block to CreateProcess when starting the application. If your resource DLL manages a service, use ResUtilSetResourceServiceStartParameters and ResUtilSetResourceServiceEnvironment before bringing the service online.
If these are both true, GetComputerNameEx returns the specified cluster name from the environment space based on NameType. If these are not true, GetComputerNameEx returns the name of the local computer. For more information about clustering, see Windows Clustering.

Requirements
Windows NT/2000: Requires Windows 2000 or later.
Windows 95/98: Unsupported.
Header: Declared in Winbase.h; include Windows.h.
Library: Use Kernel32.lib.
Unicode: Implemented as Unicode and ANSI versions on Windows 2000.

See Also
System Information Overview, System Information Functions, COMPUTER_NAME_FORMAT, GetComputerName, ResUtilGetEnvironmentWithNetName, ResUtilSetResourceServiceStartParameters, ResUtilSetResourceServiceEnvironment, SetComputerName, SetComputerNameEx

Built on Thursday, October 12, 2000Requirements
Windows NT/2000: Requires Windows 2000 or later.
Windows 95/98: Unsupported.
Header: Declared in Winbase.h; include Windows.h.
Library: Use Kernel32.lib.
Unicode: Implemented as Unicode and ANSI versions on Windows 2000.
wangj2001 2002-08-29
  • 打赏
  • 举报
回复
这是获得用户名,而因该从登陆win2000server用户名,来获得客户端的机器名
Chiun 2002-08-29
  • 打赏
  • 举报
回复
GetUserName is what you need.
WadeHan 2002-08-29
  • 打赏
  • 举报
回复
LookupAccountName
The LookupAccountName function accepts the name of a system and an account as input. It retrieves a security identifier (SID) for the account and the name of the domain on which the account was found.

BOOL LookupAccountName(
LPCTSTR lpSystemName, // system name
LPCTSTR lpAccountName, // account name
PSID Sid, // security identifier
LPDWORD cbSid, // size of security identifier
LPTSTR DomainName, // domain name
LPDWORD cbDomainName, // size of domain name
PSID_NAME_USE peUse // SID-type indicator
);
Parameters
lpSystemName
[in] Pointer to a null-terminated string specifying the system. This string can be the name of a remote computer. If this string is NULL, the account name is looked up on the local system.
lpAccountName
[in] Pointer to a null-terminated string specifying the account name.
Sid
[out] Pointer to a buffer receiving the SID structure that corresponds to the account name, pointed to by the lpAccountName parameter. If this parameter is NULL, the function returns the required buffer size.
cbSid
[in, out] Pointer to a variable. On input, this value specifies the size, in bytes, of the Sid buffer. If the function fails because the buffer is too small, this variable receives the required buffer size. If the Sid parameter is NULL, this parameter must be zero.
DomainName
[out] Pointer to a buffer receiving the name of the domain where the account name is found. If this parameter is NULL, the function returns the required buffer size.
cbDomainName
[in, out] Pointer to a variable. On input, this value specifies the size, in TCHARs, of the DomainName buffer. If the function fails because the buffer is too small, this variable receives the required buffer size, including the terminating null character. If the DomainName parameter is NULL, this parameter must be zero.
peUse
[out] Pointer to a SID_NAME_USE enumerated type indicating the type of the account when the function returns.
Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks
The LookupAccountName function attempts to find a SID for the specified name by first checking a list of well-known SIDs. If the name does not correspond to a well-known SID, the function checks built-in and administratively defined local accounts. Next, the function checks the primary domain. If the name is not found there, trusted domains are checked.

Windows 2000: In addition to lookup local accounts, local domain accounts, and explicitly trusted domain accounts, LookupAccountName can look up the name for any account in any domain in the Windows 2000 forest.

Requirements
Windows NT/2000: Requires Windows NT 3.1 or later.
Header: Declared in Winbase.h; include Windows.h.
Library: Use Advapi32.lib.
Unicode: Implemented as Unicode and ANSI versions on Windows NT/2000.

kingzai 2002-08-29
  • 打赏
  • 举报
回复
The computer might (often will) have at least two different names:
one for NetBIOS, which you can retrieve with GetComputerName, and
another for TCP/IP, which you can retrieve with gethostname().

16,470

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧