Results 1 to 3 of 3
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Computer identity

    In Win95/WordSR2/VBA How do I determine the name of the user's computer?

    My application (in theory) scours the LAN, visiting every beige box on a user's desk. (My beige box happens to be a 233MHz with twin 20G drives). On each computer it scours the drives (so, in my case 2 drives), drills down through directories, files etc.

    I build a result string, nested, files within paths within drives within computers within the LAN.

    Right now I use the 26 drive letters to identify each active drive on a computer, but I want to tag THESE 26 drives with a name local to THIS beige box.

    I'm using the code below as an interim measure
    <pre> strComputerBody = strComputerBody & strIdentifier(Application.UserName)
    </pre>

    since I own only one beige box at home.

    What would be more appropriate as a means of identifying a specific beige box?


    In RegEdit under HKEY_LOCAL_MACHINE I see nothing that suggests a name for this beige box.

    A search for "name" lead me to "InfName" and the file "Machine.inf". Hmmmm. Very interesting. Must come back to that ......


    I see that I am (not) logged on under "username" as "cgreaves", but that's more who is sitting AT the beige box, rather than what IS the beige box.

    (... searching ......)



    How about
    <pre> HKEY_LOCAL_MACHINE
    System
    Current control set
    Control
    Computername
    Computername = "CHRISTOG"
    </pre>



    <pre>Sub GetUserInfo()
    Dim strKey As String
    strKey = "HKEY_CURRENT_USERSoftwareMicrosoftMS Setup (ACME)User Info"
    Dim aname
    aname = System.PrivateProfileString("", strKey, "DefName")
    MsgBox aname
    strKey = "HKEY_LOCAL_MACHINESystemCurrentcontrolsetControlC omputernameComputername"
    aname = System.PrivateProfileString("", strKey, "Computername")
    MsgBox aname
    End Sub
    </pre>


  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Computer identity

    Chris, the following functions should work. It relies on API calls. It should be ok with NT as well.<pre>Private Declare Function GetComputerName Lib "kernel32" _
    Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

    Public Declare Function GetUserName Lib "advapi32.dll" _
    Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    '
    Function ReturnComputerName() As String
    Dim rString As String * 255, sLen As Long, tString As String
    tString = ""
    On Error Resume Next
    sLen = GetComputerName(rString, 255)
    sLen = InStr(1, rString, Chr(0))
    If sLen > 0 Then
    tString = Left(rString, sLen - 1)
    Else
    tString = rString
    End If
    On Error GoTo 0
    ReturnComputerName = UCase(Trim(tString))
    End Function
    '
    Function ReturnUserName() As String
    Dim rString As String * 255, sLen As Long, tString As String
    tString = ""
    On Error Resume Next
    sLen = GetUserName(rString, 255)
    sLen = InStr(1, rString, Chr(0))
    If sLen > 0 Then
    tString = Left(rString, sLen - 1)
    Else
    tString = rString
    End If
    On Error GoTo 0
    ReturnUserName = UCase(Trim(tString))
    End Function</pre>

    As it is Easter, you get two for the price of one.

    Andrew

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Computer identity

    Thanks. How do they compare to my "profilestring" device?

    What are the advantages? I have all weekend to ponder and examine .....

Posting Permissions

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