Lenguaje de programación Borland Delphi
Función en Delphi que obtiene el nombre del PC/Equipo en la red:
function obtenerNombrePC () : string;
var
nombre: String;
DatosSocket: WSAData;
begin
WSAStartup($0101, DatosSocket);
SetLength(nombre, MAX_PATH);
gethostname(PChar(Nombre), MAX_PATH);
SetLength(nombre, StrLen(PChar(nombre)));
result := nombre;
end;
Un ejemplo de utilización:
procedure TformNuevoCatalogo.bCarpetaRedClick(Sender: TObject);
var
unidad, seleccion : string;
begin
seleccion := SeleccionarCarpeta;
seleccion := IncludeTrailingPathDelimiter (seleccion);
if seleccion <> '' then
begin
txtRed.Text := seleccion;
unidad := ExtractFileDrive(seleccion);
obtenerDatosUnidad(unidad);
txtNombreCatalogo.Text := '';
if (Length (unidad) > 0) then
if unidad [1] <> '\' then
begin
txtNombreCatalogo.Text := obtenerNombrePC + ' - ' + unidad[1] + ' - ' + etiqueta;
txtDescripcion.Text := txtNombreCatalogo.Text;
end;
end;
end;
Publicado el: 2005-09-18