Prevent WNetAddConnection2 class which allows prohibited user to access shared folder

前端 未结 2 1895
旧巷少年郎
旧巷少年郎 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: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.

提交回复
热议问题