Is there any code Snippit that can retreve tmy computers name ?
Printable View
Is there any code Snippit that can retreve tmy computers name ?
I am running NT
..and the code to use it (from ApiSystem classCode:'\\ To get/set the local computer name...
Private Const MAX_COMPUTERNAME_LENGTH = 15
Private Declare Function GetComputername Lib "kernel32.dll" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Function SetComputername Lib "kernel32.dll" Alias "SetComputerNameA" (ByVal lpBuffer As String) As Long
HTH,Code:Public Property Let ComputerName(ByVal newName As String)
Dim lRet As Long
If LenB(newName) > (MAX_COMPUTERNAME_LENGTH) Then
'Computer length exceeds MAX_COMPUTERNAME_LEMGTH
Exit Property
End If
lRet = SetComputername(newName)
If Err.LastDllError <> 0 Then
'error occured
End If
End Property
Public Property Get ComputerName() As String
Dim sTmp As String
Dim lRet As Long
sTmp = String(MAX_COMPUTERNAME_LENGTH, 0)
lRet = GetComputername(sTmp, Len(sTmp))
If Err.LastDllError <> 0 And Err.LastDllError <> 203 Then
'error occured
Else
ComputerName = Left$(sTmp, InStr(sTmp, Chr$(0)) - 1)
End If
End Property
Duncan
VB Code:
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long Private MachineName As String Private Sub GetMachineName() Dim sBuffer As String Dim lSize As Long sBuffer = Space$(255) lSize = Len(sBuffer) Call GetComputerName(sBuffer, lSize) If lSize > 0 Then MachineName = Left$(sBuffer, lSize) Else MachineName = vbNullString End If End Sub
Even easier:
environ("COMPUTERNAME")
returns
Computer Name
yrwyddfa does that code work on 98, because i am working at home 2 nite, and i cant get it 2 work
this is what i tryed
Private Sub CommandButton1_Click()
MsgBox Environ("COMPUTERNAME")
End Sub
just use the api call.... seems to work everywhere i try it .....
admitedly that has only been nt & 2000 but i'm fairly sure it will work
if you try this:
VB Code:
for n = 1 to 254 debug.print environ(n) next
it will list all of the environment variables for the platform you run it on.
I cannot check '98 myself because I don't have access to a copy.