Languages :: Delphi :: GetComputerName not work on win98? |
|||
| By: progGoon |
Date: 07/04/2003 00:00:00 |
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 | 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 | 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 | 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 | 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 | 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 |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








