Within a VB.NET program, I want to read files from a filesystem, then write a compressed version of those files to a remote, secure fileshare, using different credentials.
The analogous operation at the cmd prompt is:
net use s: \\server\share /user:foo P@ssw0rd
copy a+b | compress > s:\foo.bin
net use s: /delete
Is this possible? How? (don't worry about the compression and file i/o. My interest is in the security parts.)
Do I do it with WindowsImpersonationContext
?
EDIT: you're right, I don't really want to map a drive; what I want to do is access a share with credentials that are not the default credentials. The app gets run by all sorts of users, and they don't have write access to the share normally. Just for the purposes of this single file, I want to allow the users to write to the share.
So how do I write a single file to a share, using alternative credentials? Keep in mind that I need the default credentials or identity to read the files that act as input to the compression.
UserX reads files a1 and b1 as UserX, writes file c1 as UserA
UserY reads files a2 and b2 as UserY, writes file c2 as UserA
Is this making sense?
I know I can create a file on a share directly. The issue is how to do that with alternative credentials? I know how to pass alt creds when creating a share, which is why I introduced the idea of creating a share. I don't really need the share, because it is done only for a single file, and only within a program.
And I know I could create the file first, then copy the file to the share. I don't want to do that because it's a large file and I'd like to stream it once.