Re: Windows machine name

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Randy Birch (rgb_removethis_at_mvps.org)
Date: 08/11/04


Date: Wed, 11 Aug 2004 13:21:36 -0400

Most APIs have constants defined or referenced that specify the particular
size of the string. In the case of GetComputerName lpBuffer is defined as
having a length of MAX_COMPUTERNAME, which the C headers defines as 16
characters, so:

Private Const MAX_COMPUTERNAME As Long = 16

   Dim tmp As String

  'return the name of the computer
   tmp = Space$(MAX_COMPUTERNAME)

   If GetComputerName(tmp, Len(tmp)) <> 0 Then
      GetLocalComputerName = TrimNull(tmp)
   End If

The full code is at http://vbnet.mvps.org/code/core/getcomputername.htm

-- 
Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.
"Bob Butler" <tiredofit@nospam.com> wrote in message
news:O0K2nw7fEHA.636@TK2MSFTNGP12.phx.gbl...
: "Joe" <Joe@discussions.microsoft.com> wrote in message news:5CFFF074-
: 2441-47A7-80A5-073861764C3B@microsoft.com
: > Bob,
: >
: > When setting buffer sizes, how do you know how large to make them?
:
: There is actually a constant that could be used; most API calls are
: documented as to the sizes needed somewhere.  I used 512 in that example
: which is overkill since system names are never going to be anywhere near
: that.
:
: -- 
: Reply to the group so all can participate
: VB.Net... just say "No"
:

Quantcast