Windows Service cannot access mapped drive

enesaga

New member
Joined
Dec 6, 2005
Messages
1
Programming Experience
1-3
I wrote a service that monitors filesystem changes in VB.NET 2003. It works fine with local drives and network shares if i use UNC path. When i try to use the mapped drive (Z:) i get an error message that drive is invalid.
Service runs under the same account that i logon to windows with and user account has domain admin rights.

I used WMI, FSO, WNetGetConnection, WNetGetUniversalName to try to get UNC path from the mapped drive and give it to FileSystemWatcher and all of these methods work fine if executed from a windows forms app, but return nothing (do not generate an error either) when run from the service.

I am using FileSystemWatcher, and if i just give it a drive letter of the mapped drive it says drive is invalid when run from service, but when i use the same code from windows forms app FileSystemWatcher accepts the mapped drive. I thought i could at least get the UNC path from the mapped drive and give that to the FileSystemWatcher, but can't retrieve the UNC path either.

Any help for a workaround is appreciated.
 
i am having basically the same problem and it seems it is related to this post as well: http://www.vbdotnetforums.com/showthread.php?t=4773

and in this post: http://www.vbdotnetforums.com/showthread.php?t=4524 the poster seems to have found a solution (impersonation), but does not explain how to go about implementing it.

it seems to me, services run under various accounts vs whatever the user account is for an applicaton. the default, being "local system" appears to not have suffecient privileges to map to, copy to, or access files over the network.

i have tried setting up my service, both through installation, and manually in services.msc, as administrator on my local box, which has permissions to access these resources. however access is still denied. when i try setting the service up as a user on the destination box, it will not even register, which does make sense.

currently i am at a bit of stand still. if, even under the administrator account (which reads as ./administrator in the snap in) i cannot access mapped files how can i indeed do it at all?

i do know know how to impersonate user accounts or if this process falls under the service installer or within the service code itself.

if any one knows any good links (i have been googling for a while now) related windows service permissions and network communication or impersonation please let us know. thanks.
 
Back
Top