|
-
Jul 26th, 2005, 05:34 AM
#1
Thread Starter
Lively Member
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 !!!
Last edited by icongroup2003; Jul 26th, 2005 at 08:20 PM.
-
Jul 26th, 2005, 05:43 AM
#2
Addicted Member
Re: Help on retrieving Local Computer Name
-
Jul 26th, 2005, 05:47 AM
#3
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
-
Jul 26th, 2005, 06:39 AM
#4
New Member
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
-
Jul 26th, 2005, 08:20 PM
#5
Thread Starter
Lively Member
Re: Help on retrieving Local Computer Name{RESOLVED]
Thanks for the help. It solved my simple problem.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|