I am connecting to an unc server (\blablub\share) from my program (written in c++). Right now i am using WNetUseConnection Function to connect to the server. Now i want to limit the access only to the program. Because right now it is possible to access the unc server using the explorer after the connection has been established. But i want to limit the access开发者_StackOverflow中文版 (especially for file write operations) only to the program. How do i do that?
Use WNetAddConnection3
and leave NETRESOURCE::lpLocalName
0. This does the heavy work of WNetUseConnection
but doesn't add a drive letter. Therefore, you'll still need to use \\Server\Share\File
names in your program.
Don't forget to WNetCancelConnection2
when your program exits. Of course, while your program runs, the connection exists. That's intentional. Security works at user level, not program level. If you really, really don't want this, you'll have to impersonate the user account you use in WNetAddConnection3
.
精彩评论