Retrieve computer name

sparx

Morphed Human
Local time
Yesterday, 20:52
Joined
Jul 22, 2002
Messages
80
I would like to know the function that would return the computer name that is currently running the database.

Any and all held is greatly appreciated.

TIA,

Erik
 
Do you mean the computer ID that the user is logged into?

Col
 
Yes that is correct
 
Code:
Function ComputerNumber() As String

    'Returns the computername
    Dim lngLen As Long, lngX As Long, strCompName As String

    lngLen = 16
    strCompName = String$(lngLen, 0)
    lngX = apiGetComputerName(strCompName, lngLen)
    
    If lngX <> 0 Then
        ComputerNumber = Left$(strCompName, lngLen)
    Else
        ComputerNumber = ""
    End If
    
        
End Function
 
I would need this function to be able to be written in VBscript.
Is this possible?
 
Here is what I have so far, it is very basic, but I am not too familiar with VBscript.

Dim PCMAKE 'Define the variable
Dim PCMODEL
DIM PCTAG

PCMAKE = InputBox("Enter PC Manufacturer or Clone:") 'Get the users name
PCMODEL = InputBox("Enter PC Model :")
PCTAG = InputBox("Enter PC Service Tag :")
WScript.echo PCMAKE &" / " & PCMODEL &" / " & PCTAG
Dim lngLen
Dim lngX
Dim strCompName
dim ComputerNumber

lnglen = 16
strCompName = String(lngLen, 0)
ComputerNumber = WGetComputer(strCompName, lngLen)


msgbox computernumber


It gives me a typemismatch error when it calls the 'WGetComputer' function
 
You've lost me now.:confused:

The code I posted will get the PC ID.

Col
 
sparx said:
It gives me a typemismatch error when it calls the 'WGetComputer' function

You need to have the API Declaration.

Code:
    Public Declare Function WGetComputer Lib "kernel32" Alias _
        "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
 
What about the simple Environ funciton?
Code:
Public Function ComputerName()
    MsgBox Environ("computername")
End Function

Public Function UserName()
    MsgBox Environ("username")
End Function
 
Mile-O-Phile said:


You need to have the API Declaration.

Code:
    Public Declare Function WGetComputer Lib "kernel32" Alias _
        "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Mile-o is right - my appologies:rolleyes: I forgot that bit.

Col
 
ghudson said:
What about the simple Environ funciton?

That's one I hadn't seen before. Thanks, ghudson.

Out of interest, and since my Help ain't working, what other system variables are possible?
 
The attached is something I put together last year when I first discovered the Environ function. Environ is a pretty resourceful function for obtaining user system settings. Using the numeric arguments can produce different results depending on the users version of Windows. I prefer to use the "text" of the argument like Environ("computername") instead of Environ(8).

HTH
 

Attachments

I am not sure how to get it to you, but I have an Access 2000 form (VB written) that does this for you. You just select the db path and it will tell you the CPU id and the NT log in id
 

Users who are viewing this thread

Back
Top Bottom