473,322 Members | 1,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 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 4482
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Maverick | last post by:
I'm trying to get the " Computer Name " of a client accessing my web site, is there a way to do this ? not ip... tia
8
by: Steven Van Dyke | last post by:
Hi I need a code snippet to determine if my computer is connected to a network or not. There's probably a System.Net function for it, but I cannot find it. Thanks, Steve
3
by: Jinu | last post by:
Hello Will be very helpful if anyone can share the idea o 'how to access a computer in a LAN using .NET Thank yo Jinu.
6
by: dbuchanan | last post by:
I have a Windows Forms application that accesses SQL Server 2k from a small local network. The application has been used for weeks on other systmes but a new install on a new machine retruns...
40
by: Jeff | last post by:
I have a system on a network and want to determine if anyone is currently connected to the back-end files. An interesting twist is that I have noticed that some users can be connected (have the...
0
by: sonu | last post by:
I have following client side code which i have used in my asp.net project SummaryFeatured Resources from the IBM Business Values Solution Center WHITEPAPER : CRM Done Right Improve the...
4
by: Noy B | last post by:
Hi, I have developed a small application that is using a MSAccess DB. the problem is that it was developed on a machine where the application and the DB are both located. now it needs to be...
4
by: wickedweapon | last post by:
Hi, I'm trying to access a remote computer and view its running processes thorugh WMI by using a script on my system but i keep getting "RPC server unavailable" error.I have changed the COM...
1
by: vabh | last post by:
Hello, My computer is connected in LAN and so many other computers too. So, now i want to access any .exe file of any other computer. Before that i am accessing the Computer Name and IPAddress...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.