|
-
Nov 16th, 2000, 02:55 PM
#1
Thread Starter
Need-a-life Member
I'm making an app that would work on a net. As there would be multiple instances os this app loaded in different machines, I would like to know which are them. So, is there any way to get the computer's name (or ID, or whatever it's called) that indentifies it within the net?
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Nov 16th, 2000, 04:56 PM
#2
Junior Member
If you want it's ID you can go: Start->Settings->Control Panel and DoubleClick on Network then click on the Identification Tab which will have your Computers ID and a couple other things.
-
Nov 16th, 2000, 04:57 PM
#3
Junior Member
Or do you want the computers IP address?
-
Nov 16th, 2000, 05:23 PM
#4
Fanatic Member
It sounds like you mean IP...which you would get by placing a winsock control on the form and placing this code:
Code:
Text1.TExt = Winsock1.LocalIP
or
Code:
'Posted By Matthew
Public Const WS_VERSION_REQD = &H101
Public Const WS_VERSION_MAJOR = WS_VERSION_REQD \ &H100 And &HFF&
Public Const WS_VERSION_MINOR = WS_VERSION_REQD And &HFF&
Public Const MIN_SOCKETS_REQD = 1
Public Const SOCKET_ERROR = -1
Public Const WSADescription_Len = 256
Public Const WSASYS_Status_Len = 128
Public Type HOSTENT
hName As Long
hAliases As Long
hAddrType As Integer
hLength As Integer
hAddrList As Long
End Type
Public Type WSADATA
wversion As Integer
wHighVersion As Integer
szDescription(0 To WSADescription_Len) As Byte
szSystemStatus(0 To WSASYS_Status_Len) As Byte
iMaxSockets As Integer
iMaxUdpDg As Integer
lpszVendorInfo As Long
End Type
Public Declare Function WSAGetLastError Lib "WSOCK32.DLL" () As Long
Public Declare Function WSAStartup Lib "WSOCK32.DLL" (ByVal wVersionRequired&, lpWSAData As WSADATA) As Long
Public Declare Function WSACleanup Lib "WSOCK32.DLL" () As Long
Public Declare Function gethostname Lib "WSOCK32.DLL" (ByVal hostname$, ByVal HostLen As Long) As Long
Public Declare Function gethostbyname Lib "WSOCK32.DLL" (ByVal hostname$) As Long
Public Declare Sub RtlMoveMemory Lib "kernel32" (hpvDest As Any, ByVal hpvSource&, ByVal cbCopy&
Function hibyte(ByVal wParam As Integer)
hibyte = wParam \ &H100 And &HFF&
End Function
Function lobyte(ByVal wParam As Integer)
lobyte = wParam And &HFF&
End Function
Sub SocketsInitialize()
Dim WSAD As WSADATA
Dim iReturn As Integer
Dim sLowByte As String, sHighByte As String, sMsg As String
iReturn = WSAStartup(WS_VERSION_REQD, WSAD)
If iReturn <> 0 Then
MsgBox "Winsock.dll Error."
End
End If
If lobyte(WSAD.wversion) < WS_VERSION_MAJOR Or (lobyte(WSAD.wversion) = _
WS_VERSION_MAJOR And hibyte(WSAD.wversion) < WS_VERSION_MINOR) Then
sHighByte = Trim$(Str$(hibyte(WSAD.wversion)))
sLowByte = Trim$(Str$(lobyte(WSAD.wversion)))
sMsg = "Windows Sockets version " & sLowByte & "." & sHighByte
'sMsg = sMsg & " winsock.dll tarafindan desteklenmiyor. "
MsgBox sMsg
End
End If
End Sub
Public Function CurrentIP(ReturnExternalIP As Boolean)
Dim hostname As String * 256
Dim hostent_addr As Long
Dim host As HOSTENT
Dim hostip_addr As Long
Dim temp_ip_address() As Byte
Dim i As Integer
Dim ip_address As String
Dim IP As String
If gethostname(hostname, 256) = SOCKET_ERROR Then
MsgBox "Windows Socket Error " & Str(WSAGetLastError())
Exit Function
Else
hostname = Trim$(hostname)
End If
hostent_addr = gethostbyname(hostname)
If hostent_addr = 0 Then
MsgBox "Winsock.dll error."
Exit Function
End If
RtlMoveMemory host, hostent_addr, LenB(host)
RtlMoveMemory hostip_addr, host.hAddrList, 4
Do
ReDim temp_ip_address(1 To host.hLength)
RtlMoveMemory temp_ip_address(1), hostip_addr, host.hLength
For i = 1 To host.hLength
ip_address = ip_address & temp_ip_address(i) & "."
Next
ip_address = Mid$(ip_address, 1, Len(ip_address) - 1)
Internal = TheIP ' Send ONLY the External IP to the CurrentIP Function
EXTERNAL = ip_address ' Send the External IP to the function parameter External
TheIP = ip_address ' Send LAN IP to the function para Internal
ip_address = ""
host.hAddrList = host.hAddrList + LenB(host.hAddrList)
RtlMoveMemory hostip_addr, host.hAddrList, 4
Loop While (hostip_addr <> 0)
If ReturnExternalIP = True Then
CurrentIP = EXTERNAL
Else
CurrentIP = Internal
End If
End Function
Sub SocketsCleanup()
Dim lReturn As Long
lReturn = WSACleanup()
If lReturn <> 0 Then
MsgBox "Socket Error " & Trim$(Str$(lReturn)) & " occurred In Cleanup "
End
End If
End Sub
Private Sub Command1_Click()
SocketsInitialize
Text1.Text = CurrentIP(True)
End Sub
Gl,
D!m
-
Nov 16th, 2000, 05:49 PM
#5
Thread Starter
Need-a-life Member
First of all, thanx Wonderer. I've already known that. However I would need my App to determine that, not me.
Second of all, Dim, I meant the "friendly name". This is why as a Supervisor you could realize easier which is the machine connected if he/she reads the name.
And I couldn't try the code you posted 'cos I couldn't find the RtlMoveMemory Subroutine. Sth was wrong with the declaration and I could not find it in the Api Viewer.
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Nov 16th, 2000, 09:03 PM
#6
Member
Get the computer name
It is very useful for service / software provider to get the machine's identification.
Intel has got a solution: "processor ID". However, due to objection for reason of privacy, the facility was disabled (correct me if I were wrong).
Anyone know how to turn on the feature from program (maybe visual basic or calling a API) so that it can be obtained.
Besides using the built in processor ID, I can only think of setting up some sort of identification by own software in somewhere on the PC, such as registry, then read it later for identification. However, this method is still subject to be changed by end user since it can be changed by end user with sufficient technical skill.
Finally, the microsoft provided "computer name" field which we entered at networking options at control panel is the last resort. But it can also be changed. No matter how, anyone knows how to read it ?
-
Nov 17th, 2000, 12:31 AM
#7
Thread Starter
Need-a-life Member
I've already found how to get the computer's name. However, I can't post it now 'cos I left the code at work. If anyone needs it, let me know and I will post it. Anyway, I'll post it later at work (if I remember)
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Nov 17th, 2000, 12:19 PM
#8
Thread Starter
Need-a-life Member
Ok, if anybody needs it, here it's the code to get the host name:
-in a bas module or whatever -
Code:
Option Explicit
Private Const WSADescription_Len = 256
Private Const WSASYS_Status_Len = 128
Public Const SOCKET_ERROR As Long = -1
Private Type WSADATA
wversion As Integer
wHighVersion As Integer
szDescription(0 To WSADescription_Len) As Byte
szSystemStatus(0 To WSASYS_Status_Len) As Byte
iMaxSockets As Integer
iMaxUdpDg As Integer
lpszVendorInfo As Long
End Type
Public Declare Function gethostname Lib "WSOCK32.DLL" (ByVal HostNAme$, _
ByVal HostLen As Integer) As Long
Public Declare Function WSAGetLastError Lib "WSOCK32.DLL" _
() As Long
Private Declare Function WSAStartup Lib "WSOCK32.DLL" (ByVal _
wVersionRequired As Integer, lpWSAData As WSADATA) As Long
Private Declare Function WSACleanup Lib "WSOCK32.DLL" () As Long
Sub SocketsInitialize()
Const WS_VERSION_REQD As Integer = &H101
Const WS_VERSION_MAJOR = &H101 \ &H100 And &HFF&
Const WS_VERSION_MINOR = &H101 And &HFF&
Const MIN_SOCKETS_REQD = 1
Dim WSAD As WSADATA
Dim iReturn As Integer
Dim sLowByte As String, sHighByte As String, sMsg As String
iReturn = WSAStartup(WS_VERSION_REQD, WSAD)
If iReturn <> 0 Then
MsgBox "Winsock.dll is not responding."
End
End If
If lobyte(WSAD.wversion) < WS_VERSION_MAJOR Or (lobyte _
(WSAD.wversion) = WS_VERSION_MAJOR And hibyte(WSAD.wversion) _
< WS_VERSION_MINOR) Then
sHighByte = Trim$(Str$(hibyte(WSAD.wversion)))
sLowByte = Trim$(Str$(lobyte(WSAD.wversion)))
sMsg = "Windows Sockets version " & sLowByte & "." & sHighByte
sMsg = sMsg & " is not supported by winsock.dll "
MsgBox sMsg:
End
End If
If WSAD.iMaxSockets < MIN_SOCKETS_REQD Then
sMsg = "This application requires a minimum of "
sMsg = sMsg & Trim$(Str$(MIN_SOCKETS_REQD)) & _
" supported sockets."
MsgBox sMsg
End
End If
End Sub
Function hibyte(ByVal wParam As Integer)
hibyte = wParam \ &H100 And &HFF&
End Function
Function lobyte(ByVal wParam As Integer)
lobyte = wParam And &HFF&
End Function
Sub SocketsCleanup()
Dim lReturn As Long
lReturn = WSACleanup()
If lReturn <> 0 Then
MsgBox "Socket error " & Trim$(Str$(lReturn)) & _
" occurred in Cleanup"
End
End If
End Sub
Function to get it
Code:
Function Get_Host_Name()
Call SocketsInitialize
Dim HostName$, HostLen&
HostLen& = 256
HostName$ = Space$(HostLen&)
If gethostname(HostName$, HostLen&) = SOCKET_ERROR Then
MsgBox "Windows Sockets error" & Str(WSAGetLastError())
Else
HostName$ = Trim$(HostName$)
HostName$ = Left$(HostName$, Len(HostNAme$) - 1)
End If
SocketsCleanup
Get_Host_Name = HostName$
End Function
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Nov 17th, 2000, 12:24 PM
#9
Thread Starter
Need-a-life Member
Fuc...in' smileys, they screwed up the code.
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Jan 19th, 2001, 05:22 AM
#10
Lively Member
Use this function to retrieve your computer's name and paste the function name under i.e. a command button :
This code goes in a module :
Public Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public Function SearchComputerName()
Dim strCompName As String
Dim lngSize As Long
strCompName = Space(255)
lngSize = 255
Call GetComputerName(strCompName, lngSize - 1)
strCompName = TrimNull(strCompName)
MsgBox strCompName
End Function
Public Function TrimNull(MyString As String)
Dim intposition As Integer
intposition = InStr(MyString, Chr$(0))
If intposition Then
TrimNull = Left(MyString, intposition - 1)
Else: TrimNull = MyString
End If
End Function
Breaker
(VB 6.0 ENT SP3 WIN 2000 PROF)=> WORK
(VB 6.0 ENT SP3 WIN ME)=> HOME -> Upgrade to .NET is coming
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
|