Reputation: 329
It's easy to log into a Windows network share (SMB) for the whole user session (e.g. net use
, WNetAddConnection2()
etc).
Is there any similar way that will only impact my current process?
Some kind of token system, maybe?
Whole session auth is okay if there's really no alternative, but I would rather avoid a "global solution to a local problem".
Upvotes: 0
Views: 1479
Reputation: 241
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:
Upvotes: 2
Reputation: 598134
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.
Upvotes: 1