Last post Oct 01, 2011 01:11 AM by HilaNor
Sep 27, 2011 12:57 AM|HilaNor|LINK
I am developing a window service using vb.net 3.5. My service needs to write a file to a directory that located on a remote server.
I have the UNC path to the remote file server and the username password.
How do I write the code to allow me write a file to the remote server?
Sep 27, 2011 01:29 AM|sudeep_13|LINK
Before creating the file on the remote location, change the credentials of the application to the username you have and then create the file (using WindowsImpersonationContext). After file creation you can reset the application user identity and continue
the flow. Pls refer to below link for changing the application user identity to the one you wish to have
Sep 27, 2011 02:38 AM|HilaNor|LINK
This is so complicated... No easier way to do so?? no way to perform something like a "Map Network Drive" from the code?
Sep 27, 2011 09:53 AM|sudeep_13|LINK
Unfortunately its not :(. The steps I told you are pretty simple
1. Change the user context using the WindowImpersonationContext class (you can find sample code on msdn for that)
2. Create the file on the drive
3. Change the credentials back to application user account.
Oct 01, 2011 01:11 AM|HilaNor|LINK
Well, I tried to implement this soluion with no success. I got a Token=0 and the Impresonation failed.
Then, I learned from the Visual Studio Help that the Impresonation is only relevant when working on the same server and you only want to login as another user. This is not what I am trying to do.
I am trying to copy a file into another server's file system.
For example (of-course, the actual details were changed):
UNC Path: \\220.127.116.11\TestDir\
So, is there a solution for this?