visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: Delphi :: GetComputerName not work on win98?


By: progGoon U.S.A.  Date: 07/04/2003 00:00:00  English  Points: 20 Status: Answered
Quality : Excellent
Dears
i use d5 or d6 on windows 2000 Operating system.
i use the functions GetUserName and GetComputerName it works will on windows 2000 and WinXP but not work in win98 or win95 (return unkown string)
Is there any help
By: VGR Date: 07/04/2003 03:06:00 English  Type : Answer
may-be this Function GetComputerName : String;


unit GetSystem;

interface

(* TODO
FreeRes : cf X
console app identig
CPU usage ??? (perf API)
*)

Function GetHDDSerial(Drive : String) : String; // 'C:\', etc
procedure GetUserNameOrg(var username, organisation : String); // TODO
Function GetComputerName : String;
//VGR03102002 ADDed this
Function GetLogonName : String;

implementation

uses Windows, // pour type DWORD
SysUtils, // pour IntToHex()
Registry;

//How to get the serial number of HDD ? (numer seryjny dysku twardego)
Function GetHDDSerial(Drive : String) : String; // 'C:\', etc
Var VolumeSerialNumber : DWORD;
MaximumComponentLength : DWORD;
FileSystemFlags : DWORD;
SerialNumber : string;
begin
GetVolumeInformation(PChar(Drive), nil, 0, @VolumeSerialNumber, MaximumComponentLength,FileSystemFlags, nil, 0);
SerialNumber := IntToHex(HiWord(VolumeSerialNumber), 4) + '-' + IntToHex(LoWord(VolumeSerialNumber), 4);
GetHDDSerial:=SerialNumber;
end;

// How to get user name and registered organization?
Procedure GetUserNameOrg(var username, organisation : String);
var reg: TRegistry;
begin
(* TODO
reg := TRegistry.Create;
reg.RootKey:=HKEY_LOCAL_MACHINE;
If reg.OpenKey('SYSTEM',False)
then If reg.OpenKey('CurrentControlSet\Control\ComputerName\ComputerName',False)
Then GetComputerName:=reg.ReadString('ComputerName')
Else GetComputerName:='(non trouvé)'
Else GetComputerName:='(non trouvé)';
reg.Free;
*) username:='(non implémenté)'; organisation:='';
end;

// How to get user name and registered organization?
Function GetComputerName : String;
var reg: TRegistry;
begin
reg := TRegistry.Create;
reg.RootKey:=HKEY_LOCAL_MACHINE;
If reg.OpenKey('SYSTEM',False)
then If reg.OpenKey('CurrentControlSet\Control\ComputerName\ComputerName',False)
Then GetComputerName:=reg.ReadString('ComputerName')
Else GetComputerName:='(non trouvé)'
Else GetComputerName:='(non trouvé)';
reg.Free;
end;

Function GetLogonName;
var reg: TRegistry;
Begin
reg := TRegistry.Create;
reg.RootKey:=HKEY_CURRENT_USER;
If reg.OpenKey('Software',False)
then If reg.OpenKey('Microsoft\Windows\CurrentVersion\Explorer',False)
Then GetLogonName:=reg.ReadString('Logon User Name')
Else GetLogonName:='(non trouvé)'
Else GetLogonName:='(non trouvé)';
reg.Free;
End; // GetLogonName String Function

Begin { Init Part }
End.

By: sumotimor Date: 07/04/2003 03:07:00 English  Type : Comment
This is the code that I was using in a Windows 95 application. I have never tried it in Windows 98. Maybe it will help.

Rich


procedure UserName
var
HostName : PHostEnt;
schar : array[0..128] of char;
HostAddress : pchar;
begin
{Get the computer name}
GetHostName(@schar, 128);
HostName := GetHostByName(@schar);
{Get the IpAddress}
HostAddress := iNet_ntoa(PInAddr(HostName^.h_addr_list^)^);
end;


By: VGR Date: 07/04/2003 03:20:00 English  Type : Comment
yes, looks like something I used too, before passing on NT ;-)

I found the registry more reliable than envireonment variables of GetHostByName+inet_ntoa

had problems finding the IP addresses of the NICs using that kind of inet_toa function. At then end came up with something different but which works fine 8-)
By: progGoon Date: 09/04/2003 22:17:00 English  Type : Comment
Dear VGR
your code work will on windoes 98 with out any registry restriction.
i will colse the registry and test it.
Thanks
Best regards
By: VGR Date: 09/04/2003 22:36:00 English  Type : Comment
not understood

"your code work will on windoes 98 with out any registry restriction." : is this a question?

"i will colse the registry" : ???



Do register to be able to answer

EContact
browser fav
page generated in 306.435820 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page