Solved

PC name

Posted on 2002-06-20
4
182 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now