View Full Version : 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.
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.
wizard7070
05-05-2010, 01:51 PM
You could use environ
So say you want the computer name it would be
MsgBox Environ("COMPUTERNAME")
This would give you a message box, to store on a cell is the same, cell = Environ("COMPUTERNAME")
Or maybe post #2 at:
http://www.pcreview.co.uk/forums/thread-965245.php
:whistle:
Bob Phillips
05-05-2010, 03:20 PM
Or maybe post #2 at:
http://www.pcreview.co.uk/forums/thread-965245.php
:whistle:
I see you pick out the smartest posts :)
Aussiebear
05-06-2010, 02:52 AM
ROFL.
Paul_Hossler
05-06-2010, 05:21 AM
Computer Name is available
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
Paul
slamet Harto
05-07-2010, 01:57 AM
'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
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!
Bob Phillips
05-07-2010, 03:19 AM
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
Dim i As Long
i = 1
Do While Environ$(i) <> ""
Debug.Print Environ$(i)
i = i + 1
Loop
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.
mdmackillop
05-08-2010, 01:54 AM
If Solved, please mark so using the Thread Tools dropdown
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.