|
-
Mar 21st, 2002, 11:14 AM
#1
Thread Starter
Junior Member
Getting Computer Name
Is there any code Snippit that can retreve tmy computers name ?
-
Mar 21st, 2002, 11:38 AM
#2
Thread Starter
Junior Member
-
Mar 21st, 2002, 11:41 AM
#3
Frenzied Member
Code:
'\\ 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
..and the code to use it (from ApiSystem class
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
HTH,
Duncan
-
Mar 21st, 2002, 11:47 AM
#4
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
-
Mar 21st, 2002, 12:12 PM
#5
Frenzied Member
Even easier:
environ("COMPUTERNAME")
returns
Computer Name
-
Mar 21st, 2002, 02:11 PM
#6
Thread Starter
Junior Member
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
-
Mar 22nd, 2002, 10:39 AM
#7
Addicted Member
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
Due to the energy crisis, the light at the end of the tunnel has been turned off.
Sorry for any inconvenience this may cause
-
Mar 22nd, 2002, 01:23 PM
#8
Frenzied Member
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.
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
|