Hi
I implemeted a windows service.It was installed on a "Machine A" .
The job of this service is read a file from a specified folder in "Machine A" and move it to "Machine B"'s Shared folder.
"Machine B"'S Shared folder having full rights for a "User A". and i am imporsinating with "User A" to move file from "MACHINE A" to "MACHINE B".
It's throwing "Access Denied Error" Please let me know what went wrong with this?
private void MoveFile(FileInfo file)
{
try
{
if (objImp.impersonateValidUser())//immporsinate with user A
file.MoveTo("\\\\Machine B\\Shared Folder\\" + file.Name);
}
catch (Exception ex)
{
//Saev error message
}
finally
{
objImp.undoImpersonation();
}
}
Thanks
Rakesh
Loading
Kirtan PatelPosted Nov 6, 2009, 7:03 AM
you need to Map The Drive / Shared Folder First then your program can use it :)
Here's How:
- Open Windows Explorer or My Computer from the Windows Start Menu.
- From the Tools menu, click Map Network Drive…. A new Map Network Drive window opens.
- In
the Map Network Drive window, choose an available drive letter from the
dropdown list located next to the "Drive:" option. Any drives already
mapped will have a shared folder name displayed inside the dropdown
list, next to the drive letter.
- Type the name of the folder to map. This name must follow UNC. Alternatively, click the Browse… button to find the correct folder by browsing available network shares.
- Click
the "Reconnect at login" checkbox if this network drive should be
mapped permanently. Otherwise, this drive will un-map when the user
logs out of this computer.
- If the remote computer that
contains the shared folder requires a different username and password
to log in, click the "different user name" hyperlink to enter this
information.
- Click Finish.
- If the drive
letter was previously mapped to a different location, a message box
will appear asking to replace the current connection with the new one.
Click Yes to disconnect and un-map the old mapped drive.
- If
the Finish operation succeeds, the network drive will be mapped. If the
network drive cannot be mapped, ensure the folder name is spelled
correctly, that this folder was correctly set up for sharing on the
remote computer, that (if necessary) the correct username and password
have been entered, and that the computer network connections are
functioning properly.
if my answer "Helps you then Check "Do you like this answer" checkbox please :)RPosted Nov 10, 2009, 12:25 AM
Here i am using the same mechanisim what u expalined above,but programatically