如何获取计算机名称

My_first 2002-03-07 02:50:29
谢谢
...全文
62 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
amiao 2002-03-07
  • 打赏
  • 举报
回复
忘了,要先user winsock;
amiao 2002-03-07
  • 打赏
  • 举报
回复
/////得到计算机名字函数////
function GetName: string;
const
MAX = MAX_COMPUTERNAME_LENGTH;
var
Computer: array[0..MAX]of Char;
Size: DWORD;
Str : String;
begin
Size := MAX;
FillChar(Computer, MAX, 0);
GetComputerName(Computer, Size);
Str := Computer;
Result := Str;
end;
quark 2002-03-07
  • 打赏
  • 举报
回复
//==============================================================================
//取得客户端‘主机名’‘IP地址’************************************************
//==============================================================================
procedure GetClientInfo(var ClientName, IPAddress: string);
var WSAData: TWSAData;
HostEnt: PHostEnt;
begin
{no error checking...}
WSAStartup(2, WSAData);
SetLength(ClientName, 255);
Gethostname(PChar(ClientName), 255);
SetLength(ClientName, StrLen(PChar(ClientName)));
HostEnt := GetHostByName(PChar(ClientName));
with HostEnt^ do IPAddress := Format('%d.%d.%d.%d',[Byte(h_addr^[0]), Byte(h_addr^[1]), Byte(h_addr^[2]), Byte(h_addr^[3])]);
WSACleanup;
end;
dancemaple 2002-03-07
  • 打赏
  • 举报
回复
The GetComputerName function retrieves the computer name of the current system. This name is established at system startup, when it is initialized from the registry.

BOOL GetComputerName(

LPTSTR lpBuffer, // address of name buffer
LPDWORD nSize // address of size of name buffer
);


Parameters

lpBuffer

Points to a buffer to receive the null-terminated character string containing the computer name.

nSize

Points to a variable that specifies the maximum size, in characters, of the buffer. This value should be large enough to contain MAX_COMPUTERNAME_LENGTH + 1 characters.



Return Values

If the function succeeds, the return value is nonzero and the variable represented by the nSize parameter contains the number of characters copied to the destination buffer, not including the terminating null character.
dancemaple 2002-03-07
  • 打赏
  • 举报
回复
用API
GetComputerName
My_first 2002-03-07
  • 打赏
  • 举报
回复
谢谢
My_first 2002-03-07
  • 打赏
  • 举报
回复
谢谢

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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