Prevent WNetAddConnection2 class which allows prohibited user to access shared folder

前端 未结 2 1876
旧巷少年郎
旧巷少年郎 2021-01-24 18:12

I had developed C# windows application. OS is Windows 7

Requirement: is to access Network Shared Folder ‘Test’ using code with credentials using W

相关标签:
2条回答
  • 2021-01-24 18:35

    I had the same problem when I used to deploy my C# project in IIS 7.5, but it's amazing when I do to removed the logout procedure of my code. . .

    What I mean is removed function LogoutFromShare(ip,folder) server directory.

    I use ony this one LoginToOtherPC(ip, usr, pwd, folder).

    0 讨论(0)
  • 2021-01-24 18:38

    By design, connecting to a share requires access to the share - it does not require access to the root directory of the share.

    Opening the share via the Run box opens the root directory of the share, so it requires at least read access to the directory as well as to the share. The WNetAddConnection2() API, by comparison only requires access to the share.

    It has to work this way, because it is sometimes desirable to give someone access to only certain subdirectories, but not the root directory. If connecting to the share required access to the root directory this would not be possible.

    After connecting to the share, you can test access to the root directory by attempting to enumerate the files. If you get an access denied exception, the user does not have access.

    0 讨论(0)
提交回复
热议问题