Search code examples
vb.netwindows-servicesnetwork-drive

VB Windows service that maps a drive then uses it


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


Solution

  • 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.