Results 1 to 11 of 11
  1. #1
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Identify a PC (Excel)

    Hi All

    This request is specifically for Excel but I may want to use it for Access in later projects. Is there some code that will allow me to find out an individual PC's name ,say, where the excel workbook is hosted?

    Jerry
    Jerry

  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: Identify a PC (Excel)

    You could try

    strUser = Environ("Username")

    or if you have WSH enabled<pre>Function wshGetUserName()
    Dim WshNet
    Set WshNet = CreateObject("WScript.Network")
    wshGetUserName = WshNet.UserName
    Set WshNet = Nothing
    End Function</pre>


    Andrew C

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

    Re: Identify a PC (Excel)

    Apologies, the above return the UserName rather than the identity of the PC.

    Substitute ComputerName in place of UserName.

    Andrew C

  4. #4
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Identify a PC (Excel)

    Suggestion: If one has auntie virus software that does script blocking, then I'd recommend no longer using the Windoes Scripting Host. Instead, use API or WMI to get the desired info.

    I ran into this a few daze ago, running an example I found and NAV just would not let me run the criter without disabling script blocking.
    I rewrote the code to eliminate WSH.

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

    Re: Identify a PC (Excel)

    As you do have a point Howard, here is the API way :<pre> Private Declare Function GetComputerName& Lib "KERNEL32" _
    Alias "GetComputerNameA" _
    (ByVal Buff$, LenBuff&)

    Function apiComputerName() As String
    Dim strBuff As String * 255, lngAPIResult As Long
    Dim lngBuffLen As Long
    lngBuffLen = 255
    lngAPIResult = GetComputerName(strBuff, lngBuffLen)
    If lngBuffLen > 0 Then apiComputerName = Left(strBuff, lngBuffLen)
    End Function</pre>

    so compurtName = apiComputerName

    Andrew

  6. #6
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Identify a PC (Excel)

    For anyone interested, example of the Windows API method for getting computer name:

    Option Explicit

    Private Declare Function GetComputerName Lib "Kernel32" _
    Alias "GetComputerNameA" _
    (ByVal lpBuffer As String, nSize As Long) As Integer

    Const MAX_COMPUTERNAME_LENGTH = 15

    Public Function GetComputerNameAPI() As String

    ' Get the network name of the current computer:
    Dim strBuffer As String
    Dim lngSize As Long
    Dim intResult As Integer

    lngSize = MAX_COMPUTERNAME_LENGTH + 1
    strBuffer = Space$(lngSize)

    intResult = GetComputerName(strBuffer, lngSize)
    GetComputerNameAPI = Left$(strBuffer, lngSize)

    End Function

    HTH

  7. #7
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Identify a PC (Excel)

    Another point is to try to not use fixed length strings as .NET does not support the critters.

    P.S.

    Speaking of the API way, anybody know whether there is an API or WMI class/property or ... that returns the amount of memory that could be installed on a PC, not the actual ly installed memory, rather the capacity of thr mobo memory slots?

  8. #8
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Identify a PC (Excel)

    I doubt if there is any API or other function that would return that information. The Windows GlobalMemoryStatus API fills a MEMORYSTATUS structure with information such as Total physical memory, Available physical memory, Total virtual memory, etc. The operating system is concerned with how much memory is available for its use, not how much memory could theoretically be installed on the machine. Recommend refer to Owner's Manual that came with the computer,.

  9. #9
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Identify a PC (Excel)

    AIDA returns such info.
    Unless AIDA is using a built-in table of info on mobos, I would expecvt that there is a way to return such info.

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

    Re: Identify a PC (Excel)

    The following is from AIDA32 - Features
    <center>
    <hr>full hardware & software information on 85 pages built-in hardware database<hr>
    </center> so I suspect that neither the OS nor it's API are used to get the information.

    Regarding VB.NET and FixedLength strings Microsoft do supply a FixedLengthString class in VisualBasic.Compatibility Namespace which will allow emulation of fixed lenght strings.

    Your VB.NET project would need a reference to the Microsoft Visual Basic.Net Compatibility Runtime Library.

    Andrew C

  11. #11
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Identify a PC (Excel)

    Thanks Andrew et al. This piece of code works great for my specific project but the other contributions are very much welcomed

    Jerry
    Jerry

Posting Permissions

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