Help on retrieving Local Computer Name{RESOLVED]
I need a function that can return the name of the local machine.
Is there such a function already in VB ?
Like example :
'it will return the computer id/name which I am running on right now.
MyCompName = getcompname()
Please help.
I need this urgently.
Many thanks and gratitude !!!
Re: Help on retrieving Local Computer Name
Re: Help on retrieving Local Computer Name
There is an API function you can use. Here's a wrapper function for that API function.
VB Code:
Private Declare Function GetComputerName _
Lib "kernel32.dll" Alias "GetComputerNameA" ( _
ByVal lpBuffer As String, _
ByRef nSize As Long) As Long
Public Function GetCompName() As String
Dim sBuff As String
Dim nLen As Long
nLen = 215 'probably to large buffer
sBuff = Space$(nLen + 1)
If GetComputerName(sBuff, nLen) Then
GetCompName = Left$(sBuff, nLen)
Else
sBuff = Space$(nLen)
Call GetComputerName(sBuff, nLen)
GetCompName = Left$(sBuff, nLen)
End If
End Function
Re: Help on retrieving Local Computer Name
Declare Function GetUserNameA Lib "advapi32.dll" (ByVal lpBuffer As String, nSize As Long) As Long
Declare Function GetComputerNameA Lib "kernel32" (ByVal lpBuffer As String, nSize As Long) As Long
Public Function GetUserName() As String
Dim UserName As String * 255
Call GetUserNameA(UserName, 255)
GetUserName = Left$(UserName, InStr(UserName, Chr$(0)) - 1)
End Function
Public Function GetComputerName() As String
Dim UserName As String * 255
Call GetComputerNameA(UserName, 255)
GetComputerName = Left$(UserName, InStr(UserName, Chr$(0)) - 1)
End Function
'Put in module
'Call this like
'Text1.text = "Hello " & GetUserName & " On " & GetComputerName
:thumb:
Re: Help on retrieving Local Computer Name{RESOLVED]
Thanks for the help. It solved my simple problem.