Log in to a windows network share (SMB) for this process only

假如想象 提交于 2019-12-01 14:31:56

Network sessions are handled by the windows kernel as part of the smb client driver, as such they are managed per windows workstation (not the user actually), meaning that you can't access the same share with two different credentials, and you can't actually create a new network connection per process as per the limitation imposed by the windows smb client. the reason for the limitation is that Microsoft implemented share access as a filter driver, each UNC path (\share\test) to share access is stored as a shared resource to make your live as a developer and user easier. (makes share access seamless)  

a quick example of it is running net use in an elevated (run as administrator) command prompt and trying to access it in an unelevated context.

you can go either way:

  1. use samba/another userland smb implementation (there are some python based) in your software
  2. create a new winstation for each of your processes (this has a big overhead)

Network sessions (and assigned drive letters) are handled per-user, not per-process. So no, you cannot create an SMB session just for your process, unless it runs with a dedicated user account. Otherwise, you would just have to add a global connection (including the CONNECT_TEMPORARY flag, for instance) and then remove the connection (WNetCancelConnection2()) when you are finished using it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!