2 Replies - 750 Views - Last Post: 03 September 2013 - 04:45 AM Rate Topic: -----

#1 The Gothic  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 04-June 09

opened file's user name

Posted 02 September 2013 - 03:59 AM

Hi,
I want to ask you if there is any way how to get user name of user who has open file. For example:

I check if file is open or not and then show messagebox:


        Dim fs As System.IO.FileStream
        Dim sName As String = "\\file path\file.xls"

        Try

            fs = System.IO.File.Open(sName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.None)

            isOpen = False
            MsgBox("File is not open")
            fs.Dispose()

        Catch ex As Exception

            isOpen = True
            MsgBox("File is open by another user")

        End Try




and would like to show something like this:


        Dim fs As System.IO.FileStream
        Dim sName As String = "\\Cz02nas01\HP_Servers_L10\Departments\Eng&Quality\PE\PE\Transformation Table\New_PrTy_E_BOMs_History.xls"

        Try

            fs = System.IO.File.Open(sName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.None)

            isOpen = False
            MsgBox("File is not open")
            fs.Dispose()

        Catch ex As Exception

            isOpen = True
            MsgBox("File is open by " & username) '<----------------------

        End Try




Thank you

This post has been edited by The Gothic: 02 September 2013 - 04:00 AM


Is This A Good Question/Topic? 0
  • +

Replies To: opened file's user name

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3470
  • View blog
  • Posts: 11,778
  • Joined: 12-December 12

Re: opened file's user name

Posted 02 September 2013 - 04:37 AM

I may be wrong but I don't think it is easy to do this. It probably requires use of the NetFileEnumWin-API call. I would also be suspicious that permission-levels may prevent the information from being returned.
Was This Post Helpful? 0
  • +
  • -

#3 The Gothic  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 04-June 09

Re: opened file's user name

Posted 03 September 2013 - 04:45 AM

View Postandrewsw, on 02 September 2013 - 05:37 AM, said:

I may be wrong but I don't think it is easy to do this. It probably requires use of the NetFileEnumWin-API call. I would also be suspicious that permission-levels may prevent the information from being returned.


Hi Andrew,
thanks for advice. I'll have to study more theory to understand that code cause I use a few methods, components and loops to reach all my goals but my knowledge of programming is wretched : )

I'll take a look at it and we will see

Regards
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1