Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 114
Default Windows API to get network username of person with file open

Hi

I am writing code to open another Excel file. If the file is in use by
another user, I would like to use an API function to return the network
username of the person who has the file open. Any suggestions?

Thanks in advance

Paul Martin Melbourne, Australia

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Windows API to get network username of person with file open

You should be able to get away without APIs.
Open the workbook Read only, then check the WriteReservedBy property of the
workbook.


With ActiveWorkbook
If .WriteReserved = True Then
MsgBox "Opened by " & .WriteReservedBy
End If
End With


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Paul Martin" wrote in message
ups.com...
Hi

I am writing code to open another Excel file. If the file is in use by
another user, I would like to use an API function to return the network
username of the person who has the file open. Any suggestions?

Thanks in advance

Paul Martin Melbourne, Australia



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 114
Default Windows API to get network username of person with file open

Hi Bob

Thanks for the reply. Firstly, WriteReserved returns False, and
secondly, WriteReservedBy returns the Excel username. The problem with
the latter is that this does not identify the actual username. I would
like to get the network username, hence the need for an API. I've
found an API from the newsgroups that returns the network name:

Private Declare Function apiGetUserName Lib "advapi32.dll" Alias
"GetUserNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long

I can use this to get my username, but I want to get the username of
the user who has the file open that I am attempting to open through
code.

Regards

Paul

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 188
Default Windows API to get network username of person with file open

"Bob Phillips" wrote in message

You should be able to get away without APIs.
Open the workbook Read only, then check the WriteReservedBy
property of the workbook.


With ActiveWorkbook
If .WriteReserved = True Then
MsgBox "Opened by " & .WriteReservedBy
End If
End With


I could be wrong, but doesn't that just give you the name that
the machine that has opened the file has entered in
excel - tools - options?

It *should* be correct, but isn't definitively the user who is
logged in.

Of course, you could also argue that someone could log in under a
different network username anyway!

An example of the Win32 API is as follows (I think I got this from
this newsgroup, but as is often the case, I didn't record the original
source, so apologies to the OP of this function and thanks too!):

+-+-++-+-++-+-++-+-++-+-++-+-+-

Private Declare Function GetNetworkUserName Lib "advapi32.dll" Alias
"GetUserNameA" _
(ByVal lpBuffer As String, _
ByRef nSize As Long) As Long


'Get the user's login ID

Function NetworkUserName() As String

'A buffer that the API function fills with the login name

Dim sBuffer As String * 255

'Variable to hold the length of the buffer

Dim lStringLength As Long

'Initialize to the length of the string buffer

lStringLength = Len(sBuffer)

'Call the API function, which fills the buffer
'and updates lStringLength with the length of the login ID,
'including a terminating null - vbNullChar - character

GetNetworkUserName sBuffer, lStringLength

If lStringLength 0 Then

'Return the login id, stripping off the final vbNullChar

NetworkUserName = Left$(sBuffer, lStringLength - 1)

End If

End Function

+-+-++-+-++-+-++-+-++-+-++-+-+-


HTH,

Alan.

--
The views expressed are my own, and not those of my employer or anyone
else associated with me.

My current valid email address is:



This is valid as is. It is not munged, or altered at all.

It will be valid for AT LEAST one month from the date of this post.

If you are trying to contact me after that time,
it MAY still be valid, but may also have been
deactivated due to spam. If so, and you want
to contact me by email, try searching for a
more recent post by me to find my current
email address.

The following is a (probably!) totally unique
and meaningless string of characters that you
can use to find posts by me in a search engine:

ewygchvboocno43vb674b6nq46tvb



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 114
Default Windows API to get network username of person with file open

Alan

That function will return MY network login. I want the network
username of the person who has a file open that I am programatically
opening.

Paul



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Windows API to get network username of person with file open

I'm not sure if it's possible, but you may want to try posting the same question
in one of the VB newsgroups.

Well, if no one gives an acceptable answer here.

Paul Martin wrote:

Alan

That function will return MY network login. I want the network
username of the person who has a file open that I am programatically
opening.

Paul


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 114
Default Windows API to get network username of person with file open

It is possible using either NetFileGetInfo or NetFileEnum APIs (I'm not
sure which), but I haven't been able to find a suitable wrapper to
utilise them.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2007 - Open a file with more than one person xeribor Excel Discussion (Misc queries) 0 March 2nd 10 12:02 PM
Unable to save file to Windows 98 network folder jj Excel Discussion (Misc queries) 4 March 5th 05 07:59 PM
Looking for network-username with Excel macro Geert Nauta Excel Programming 1 October 4th 04 04:12 PM
Finding the Username of a user who has a shared Network file open. Ken[_23_] Excel Programming 1 September 10th 04 12:35 PM
Network detects if Windows Username is online Todd Huttenstine Excel Programming 0 July 9th 04 08:12 PM


All times are GMT +1. The time now is 02:46 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"