0

Map a network drive to be used by a service

My question is relatively similar, and I realize there are others that are.. but I can't get it to work. I am creating the service thru visual studio 2010.

I attempted to map using WNetAddConnection2- and it successfully maps and is instantly lost (check if drive is mapped right after mapping it).

So I tried something else..
I saw some information about using WSH.. I added the reference and tried using wsh... didn't work.

I tried WNetUseConnection and that failed as well.

Attempted running the service under a different profile- that didn't work

Once I actually get access to the network drive, i need to copy files from that share into a local directory.

Maybe I'm missing the boat here but If someone could give me a thorough explaination of what is actually going on and a direction to head I can probably figure it out

Community
  • 1
  • 1
GetBrutal
  • 33
  • 1
  • 10
  • Do you have to use a mapped drive? Can you just access the resource via the UNC name? – aphoria Feb 22 '12 at 19:46
  • Why do you need to map it as a drive, why not just copy the files directly from the share? – John Koerner Feb 22 '12 at 19:47
  • Well.. I did try to access it via UNC but it is telling me that I dont have access to it. server has credentials and when i attempt to start the copy it fails – GetBrutal Feb 22 '12 at 19:59
  • If you don't have access to it via the UNC then you won't have access to it as a mapped drive. Mapping the drive is not the issue you're facing. – Jesse Feb 22 '12 at 23:53

1 Answers1

0

Use the System.Security.Principal.WindowsIdentity class' Impersonate Method with the credentials of a user that has access to that drive and then try to grab the files.

NoAlias
  • 9,218
  • 2
  • 27
  • 46