如何获取本地计算机名(50分)

  • 主题发起人 主题发起人 斗士
  • 开始时间 开始时间

斗士

Unregistered / Unconfirmed
GUEST, unregistred user!
如何获取本地计算机名<br>用windows API 或 注册表?<br>哪一个更好<br>如何实现。<br>或者还有更好办法,关键在于高效、简洁。
 
RootKey := HKEY_LOCAL_MACHINE;<br>&nbsp; &nbsp; &nbsp;if OpenKey('System/CurrentControlSet/Services/VxD/VNETSUP',<br>&nbsp; &nbsp; &nbsp; &nbsp; false) then<br>&nbsp; &nbsp; &nbsp; &nbsp; Result := ReadString('ComputerName');
 
procedure TForm1.Button1Click(Sender: Tobject);<br>var<br>&nbsp; ComputerName: array[0..MAX_COMPUTERNAME_LENGTH+1] of char; &nbsp;// holds the name<br>&nbsp; Size: DWORD; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// holds the size<br>begin<br>&nbsp; {initialize the computer name size variable}<br>&nbsp; Size := MAX_COMPUTERNAME_LENGTH+1;<br><br>&nbsp; {retrieve the computer name}<br>&nbsp; if GetComputerName(ComputerName, Size) then<br><br>&nbsp; &nbsp; Edit1.Text := StrPas(Computername)<br>&nbsp; else Showmessage('Computer Name Not Found');<br>end<br><br>
 
注册表的方式可能不妥,操作系统不同,键值不相同<br>用GetComputerNaem不错,能够实现<br>谢谢
 
后退
顶部