472,127 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

Determine Computer Name That is Accessing File

I have been trying to find some API routines that will allow me to
determine the name of the computer that is accessing a file on a
server. I have found the NetFileEnum call (returns the names of the
files in use and the names of the users accessing them). I have also
found the NetConnectionEnum call (returns the name of the computer that
is accessing a share). I do not see any way of correlating the data
that these two api calls return. Can anyone point me in the right
direction? Thanks.

-Vincent

Aug 11 '06 #1
2 4404
Hi Vincent,

This function (see below) will return the name of the local computer,
if you use this routine in a client server environment you have to
place the code on the local machine.

Private Declare Function apiGetComputerName Lib "kernel32" Alias
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Integer

'Returns the computername
Function GetMachineName() As String
Dim lngLen As Long
Dim lngX As Integer
Dim strCompName As String
lngLen = 12
strCompName = String$(lngLen, 0)
lngX = apiGetComputerName(strCompName, lngLen)
If lngX <0 Then
GetMachineName = Left$(strCompName, lngLen)
Else
GetMachineName = ""
End If
End Function

If your machines have name longer than 12 characters you should adjust
the lngLen variable to for instance 18.

Good luck

Nick

It will automatically give a
Vincent wrote:
I have been trying to find some API routines that will allow me to
determine the name of the computer that is accessing a file on a
server. I have found the NetFileEnum call (returns the names of the
files in use and the names of the users accessing them). I have also
found the NetConnectionEnum call (returns the name of the computer that
is accessing a share). I do not see any way of correlating the data
that these two api calls return. Can anyone point me in the right
direction? Thanks.

-Vincent
Aug 11 '06 #2
Nick,

This is good information, but it really does not help me. I am
trying to find out the name of the computer that has a particular file
open. I need some routine that encompasses both of these pieces of
information or a way to cross-reference multiple API calls to retrieve
this information.

-Vincent

Nick 'The database Guy' wrote:
Hi Vincent,

This function (see below) will return the name of the local computer,
if you use this routine in a client server environment you have to
place the code on the local machine.

Private Declare Function apiGetComputerName Lib "kernel32" Alias
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Integer

'Returns the computername
Function GetMachineName() As String
Dim lngLen As Long
Dim lngX As Integer
Dim strCompName As String
lngLen = 12
strCompName = String$(lngLen, 0)
lngX = apiGetComputerName(strCompName, lngLen)
If lngX <0 Then
GetMachineName = Left$(strCompName, lngLen)
Else
GetMachineName = ""
End If
End Function

If your machines have name longer than 12 characters you should adjust
the lngLen variable to for instance 18.

Good luck

Nick

It will automatically give a
Vincent wrote:
I have been trying to find some API routines that will allow me to
determine the name of the computer that is accessing a file on a
server. I have found the NetFileEnum call (returns the names of the
files in use and the names of the users accessing them). I have also
found the NetConnectionEnum call (returns the name of the computer that
is accessing a share). I do not see any way of correlating the data
that these two api calls return. Can anyone point me in the right
direction? Thanks.

-Vincent
Aug 11 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Maverick | last post: by
8 posts views Thread by Steven Van Dyke | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.