Consulting

Results 1 to 12 of 12

Thread: Solved: Computer identification

  1. #1
    VBAX Regular
    Joined
    Dec 2008
    Posts
    11
    Location

    Cool Solved: Computer identification

    Hi. I am using Excel 2007. I am trying to write a VBA code that would identify each single computer (where the XL file is opened) by their specific characteristics, and store these data in specific cells of the file. The computer characteristics may be any thing (drive size, cpu number, screen display, etc.) that could differentiate computers. Do you know if this is possible? Any help at all on this problem? Thanks.

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Certainly just a "laymen coder" at best, but I think you may wish to decide what identifier you want to use first, then ask, as I think the answer would probably include API.

  3. #3
    You could use environ

    So say you want the computer name it would be

    [vba]MsgBox Environ("COMPUTERNAME")[/vba]
    This would give you a message box, to store on a cell is the same, cell = Environ("COMPUTERNAME")

  4. #4
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by GTO
    I see you pick out the smartest posts
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    ROFL.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  7. #7
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    Computer Name is available


    [VBA]
    Option Explicit
    'http://www.mvps.org/access/api/api0009.htm
    '******************** Code Start **************************
    ' This code was originally written by Dev Ashish.
    ' It is not to be altered or distributed,
    ' except as part of an application.
    ' You are free to use it in any application,
    ' provided the copyright notice is left unchanged.
    '
    ' Code Courtesy of
    ' Dev Ashish
    '
    Private Declare Function apiGetComputerName Lib "kernel32" Alias _
    "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    Function fOSMachineName() As String
    'Returns the computername
    Dim lngLen As Long, lngX As Long
    Dim strCompName As String
    lngLen = 16
    strCompName = String$(lngLen, 0)
    lngX = apiGetComputerName(strCompName, lngLen)
    If lngX <> 0 Then
    fOSMachineName = Left$(strCompName, lngLen)
    Else
    fOSMachineName = ""
    End If
    End Function
    '******************** Code End **************************

    Sub drv()
    MsgBox fOSMachineName
    End Sub
    [/VBA]

    Paul

  8. #8
    VBAX Tutor
    Joined
    Sep 2007
    Posts
    265
    Location
    [VBA]
    'This page is copyright © 2000 Paul Kuliniewicz. Copyright Information.
    'This page is at http://www.vbapi.com/ref/g/getcomputername.html

    Private Declare Function GetComputerName Lib "kernel32.dll" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    Sub PCName()

    ' Display the computer's name
    Dim compname As String, retval As Long ' string to use as buffer & return value
    compname = Space(255) ' set a large enough buffer for the computer name
    retval = GetComputerName(compname, 255) ' get the computer's name
    ' Remove the trailing null character from the strong
    compname = Left(compname, InStr(compname, vbNullChar) - 1)
    MsgBox compname ' display nameCategory: System Information
    End Sub
    [/VBA]

  9. #9
    VBAX Contributor
    Joined
    Feb 2009
    Posts
    103
    Location
    If you just want to get these info: "The computer characteristics may be any thing (drive size, cpu number, screen display, etc.) that could differentiate computers."

    I suggest use VBscript or powershell.
    try searching in google: vbscript get drive size

    results will give you an idea on how to get started.
    But if you insist in using vba, then it will be a rough road ahead..
    Goodluck!

  10. #10
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    These API, scripting solutions are all very well and good, but with the Environ option now available, it seems overkill. In addition, some sites will not allow scripting so they might not work.

    You can see all of the Environ variables with

    [vba]

    Dim i As Long

    i = 1

    Do While Environ$(i) <> ""

    Debug.Print Environ$(i)
    i = i + 1
    Loop
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  11. #11
    VBAX Regular
    Joined
    Dec 2008
    Posts
    11
    Location
    For all who replied and provided solutions and comments. Thanks so much everybody for your advices. I solved my problem with both Environ and Drive id. Thanks again.

  12. #12
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    If Solved, please mark so using the Thread Tools dropdown
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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