BCB中如何获取计算机名?(100分)

  • 主题发起人 主题发起人 FinalLeon
  • 开始时间 开始时间
F

FinalLeon

Unregistered / Unconfirmed
GUEST, unregistred user!
BCB中如何获取计算机名?
 
getcomputername()
 
var
ComputerName: array[0..MAX_COMPUTERNAME_LENGTH+1] of char;
// holds the name
Size: DWORD;
// holds the size
begin
{initialize the computer name size variable}
Size := MAX_COMPUTERNAME_LENGTH+1;
{retrieve the computer name}
if GetComputerName(ComputerName, Size) then

Edit1.Text := StrPas(Computername)
else
Showmessage('Computer Name Not Found');
end
 
BOOL GetComputerName(
LPTSTR lpBuffer, // computer name
LPDWORD lpnSize // size of name buffer
);
 
var
computer:pchar
size:Dword;

Getmem(computer,255);//获取计算机名
size:=255;
GetComputername(computer,size);
Label3.Caption:=computer;
Freemem(computer);
 
char Buffer[25];
DWORD nSize = 25;
GetUserName(Buffer,&nSize);
return (String)Buffer;
 
后退
顶部