computer name
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 18

Thread: computer name

  1. #1
    Join Date
    Nov 2002
    Posts
    3

    computer name

    hi, i am new to this forum !!

    in VB6.0, is there any object i can retrieve the computer name when a user is executing a exe.

    THX
    KEith

  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Retrieve computer name

    Hi, welcome to this forum!

    You can use GetComputerName Api

    from Api-guide, a free tool you can download at www.allapi.net
    Code:
    'example by Donavon Kuhn (Donavon.Kuhn@Nextel.com)
    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
    Cesare Imperiali
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    Sep 2001
    Location
    Québec, Canada
    Posts
    1,923
    No need for API, here is a simpler method:

    Code:
    MsgBox Environ$("computername")
    JeffB
    CodeGuru VB FAQ Visual Basic Frequently Asked Questions
    VB Code color Tool to color your VB code on CodeGuru
    Before you post Importants informations to know before posting

  4. #4
    Join Date
    Jul 2001
    Posts
    430

    computer name

    How can I get a unique id of a computer which is definitely different from other computers? Is there any? thanks

  5. #5
    Join Date
    Dec 2001
    Posts
    6,332
    There are different ways to do this, depending on what you want to get. You can use the CoCreateGuid API call, or you can use the hard drive serial number to generate a code, or the installation date and time, or...

    Actually, there are many ways. To use the hard drive serial number, use the GetVolumeInformation API call. You can also mix in a name entered by the user, along with the date and time to create the unique number.

    If you distribute the app on CD (or floppy), you can use the serial number of the disc.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  6. #6
    Join Date
    Jul 2001
    Posts
    430
    thanks for your help.

    i am very interested in what u said "you can use the serial number of the disc". Please tell me how I can code to get serial number of the disc (cd or floppy).

  7. #7
    Join Date
    Sep 2001
    Location
    Québec, Canada
    Posts
    1,923
    You must use the GetVolumeInformation API:

    http://www.codeguru.com/forum/showth...hreadid=220420

    JeffB
    CodeGuru VB FAQ Visual Basic Frequently Asked Questions
    VB Code color Tool to color your VB code on CodeGuru
    Before you post Importants informations to know before posting

  8. #8
    Join Date
    Jul 2001
    Posts
    430
    thanks.

    But what i want to know now is how to code to get the id of cd or floppy disk.

  9. #9
    Join Date
    Dec 2001
    Posts
    6,332
    The GetVolumeInformation API works for CD and floppy also.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  10. #10
    Join Date
    Jan 2003
    Location
    MUMBAI
    Posts
    2

    Getting Computer Name

    The following code is not giving any output

    MsgBox Environ$("computername")

    where as the api works but i find its a lengthy code,

    pls help.

    Dennis.

  11. #11
    Join Date
    Sep 2001
    Location
    Québec, Canada
    Posts
    1,923
    Here is some documentation on Environ:

    http://www.developerfusion.com/show/1640/show.aspx

    (Use the Next >> to read the others pages)

    If it is not working, that is probably because you do not have the environnenement variable "computername", someone might have play with windows settings or you just need a reboot. If you still have problem, GetComputerName should be used instead of Environ$

    JeffB
    CodeGuru VB FAQ Visual Basic Frequently Asked Questions
    VB Code color Tool to color your VB code on CodeGuru
    Before you post Importants informations to know before posting

  12. #12
    Join Date
    Apr 2005
    Posts
    3

    Thumbs up Re: computer name

    First let's start by simplifing the code. I'm a strong believer in the less code the better.

    Why not use the Environ function.
    ==========================================================
    Code:
    Private Sub cmdGetInfo_Click()
    
        Dim strPath                  As String
        Dim strUserName         As String
        Dim strCompName       As String
        Dim strOpSystem         As String
        
       strPath = Environ("Path")
       strUserName = Environ("UserName")
       strCompName = Environ("ComputerName")
       strOpSystem = Environ("OS")
       
       lblPath = strPath
       lblUserName = strUserName & " ---- " & strCompName
       lblOpSystem = strOpSystem
    End Sub
    happy coding


    NetWiz
    Last edited by Cimperiali; May 5th, 2005 at 04:38 AM. Reason: Added Code Tags

  13. #13
    Join Date
    Oct 2004
    Posts
    8

    Re: computer name

    Easiest way of getting the Computer Name (without API's)
    1.Check Active DS Type Library is choosen (activeds.tlb)
    2.code:
    Dim objActiveDs As New ActiveDs.WinNTSystemInfo
    MsgBox objActiveDs.ComputerName

  14. #14
    Join Date
    Dec 2001
    Posts
    6,332

    Re: computer name

    Quote Originally Posted by socrates4c
    Why not use the Environ function...
    Note that Environ$() won't work for every case, so API would be more reliable.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  15. #15
    Join Date
    May 2005
    Posts
    4

    Post How do i get computer names in my Network or domain

    How can i get the computer names in my network. getting a computer name is easy. Please assist. I will be waiting. Thnx

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center