Solved

PC name

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

758 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

21 Experts available now in Live!

Get 1:1 Help Now