|
-
Mar 9th, 2000, 01:56 PM
#1
Thread Starter
New Member
I am trying to programatically find what a computer's name is on a network. Does anyone know how to do this? I guess it's a Windows API function but I really have no idea.
Thanks in advance.
-
Mar 9th, 2000, 02:13 PM
#2
Conquistador
Getting desktop
Here is an api:
put this in a module
Code:
Declare Function GetComputerName Lib "kernel32.dll" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public Function GetCompName() As String
Dim compname As String, retval As Long ' string to use as buffer & return value
compname = Space(255) ' set a large enough buffer for the computer name
retval = GetComputerName(compname, 255) ' get the computer's name
' Remove the trailing null character from the strong
compname = Left(compname, InStr(compname, vbNullChar) - 1)
GetCompName = compname
End Function
to display do this:
Code:
Text1.Text = GetCompName
ok?
-
Mar 9th, 2000, 11:25 PM
#3
Lively Member
This should work too.
Code:
sMyComputerName = Environ("COMPUTERNAME")
-
Mar 12th, 2000, 01:50 PM
#4
Conquistador
IShamel I couldn't get your example to work why 
-
Mar 12th, 2000, 01:56 PM
#5
Thread Starter
New Member
Thanks Isamal, but I couldn't get it to work either - David's ('da-silvy') code was fine.
-
Mar 12th, 2000, 02:05 PM
#6
Conquistador
-
Mar 12th, 2000, 07:47 PM
#7
Lively Member
It does not work on your machine because you do not have an Environment setting on your computer called "COMPUTERNAME"
This code will list all the Environment variables that are held on your computer.
Code:
Private Sub Command1_Click()
Dim EnvString, Indx,
Indx = 1
Do
Debug.Print Environ(Indx)
Indx = Indx + 1
Loop Until EnvString = ""
End Sub
From the list that is produced, you should be able to determine which setting holds the computer name. Then you can use this code to return the Computers Name.
Code:
sMyComputerName = Environ("PLACE ENVIRON NAME HERE")
Hope this helps.
-
Mar 13th, 2000, 09:03 AM
#8
Thread Starter
New Member
Yep Ishamel, you're right - I've got it to work now.
Thanks
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
|