function ComputerName : String; var 
   CNameBuffer  : PChar; 
  fl_loaded    : Boolean; 
  CLen         : ^DWord; begin     GetMem(CNameBuffer,255); 
    New(CLen); 
    CLen^:= 255;     fl_loaded := GetComputerName(CNameBuffer,CLen^);     if fl_loaded then 
      ComputerName := StrPas(CNameBuffer) 
    else 
      ComputerName := 'Unkown';     FreeMem(CNameBuffer,255); 
    Dispose(CLen); end; 

解决方案 »

  1.   

    我是指用winapi getcomputername()
      

  2.   

    procedure TForm1.Button1Click(Sender: Tobject);
    var
      ComputerName: array[0..MAX_COMPUTERNAME_LENGTH+1] of char; 
      Size: dword;                                              
    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;procedure TForm1.Button2Click(Sender: TObject);
    var
      ComputerName: array[0..MAX_COMPUTERNAME_LENGTH+1] of char;  // holds the name
    begin
      {copy the specified name to the ComputerName buffer}
      StrPCopy(ComputerName, Edit1.Text);  {set the computer name}
      if SetComputerName(ComputerName) then    ShowMessage('Computer Name Reset Setting will be used at next startup')
      else ShowMessage('Computer Name Not Reset');
    end;The Tomes of Delphi 3: Win32 Core API Help File by Larry Diehl