Solved

PC name

Posted on 2002-06-20
4
184 Views
Last Modified: 2010-05-02
I need get the PC Name with VB.
is it possible?
how?
0
Comment
Question by:akela11
4 Comments
 
LVL 20

Accepted Solution

by:
hes earned 50 total points
ID: 7097061
Use This

Private Const MAX_COMPUTERNAME_LENGTH As Long = 31
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Sub Form_Load()
    Dim dwLen As Long
    Dim strString As String
    'Create a buffer
    dwLen = MAX_COMPUTERNAME_LENGTH + 1
    strString = String(dwLen, "X")
    'Get the computer name
    GetComputerName strString, dwLen
    'get only the actual data
    strString = Left(strString, dwLen)
    'Show the computer name
    MsgBox strString
End Sub
0
 

Author Comment

by:akela11
ID: 7097103
it works perfect ( at first run ;)  )
thanks a lot!
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 7097105
This works on NT/2000 machines:

debug.print environ("computername")
0
 
LVL 5

Expert Comment

by:rpai
ID: 7097109
Public Declare Function GetComputerName Lib "kernel32.dll" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Private Sub GetCompName()
Dim CompName As String
Dim retVal   As String

'-- Set a large buffer for the computer name
CompName = Space(255)

'-- Get the computer's name
retVal = GetComputerName(CompName, 255)

'-- Remove the trailing null character from the strong
CompName = Left(CompName, InStr(CompName, vbNullChar) - 1)
Debug.Print CompName

End Sub
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question