Network Share\Mapped Drive Access from a windows service

G

Guest

I am attempting to write a vb.net windows service that will automate various
file movements on my network. When I attempt to access files on a mapped
drive or UNC file share, I get exceptions claiming that the file is not
there. However if I copy the file path directly in to explorer it pops right
up.
I know that my service is running as local system and this must be causing
the problems. When I write the windowsidentity.getcurrent().name to the event
log, it reads as NT AUTHORITY\SYSTEM. I have tried impersonation with no
success. The service stops immediatley when attempting to run this line:

Private Declare Auto Function LogonUser Lib "advapi32.dll" (ByVal
lpszUsername As [String], _
ByVal lpszDomain As [String], ByVal lpszPassword As [String], _
ByVal dwLogonType As Integer, ByVal dwLogonProvider As Integer, _
ByRef phToken As IntPtr) As Boolean



**As an added bonus, the file share I am trying to access is on an AS400. I
have mapped the drive and am attempting to use the pre-mapped drive. It would
be nice to authenticate directly to the AS400 from my code, and the use the
UNC share name for the directory on the 400.
 
K

Ken Tucker [MVP]

Hi,

http://www.dotnet247.com/247reference/msgs/28/144136.aspx

Ken
--------------------
I am attempting to write a vb.net windows service that will automate various
file movements on my network. When I attempt to access files on a mapped
drive or UNC file share, I get exceptions claiming that the file is not
there. However if I copy the file path directly in to explorer it pops right
up.
I know that my service is running as local system and this must be causing
the problems. When I write the windowsidentity.getcurrent().name to the
event
log, it reads as NT AUTHORITY\SYSTEM. I have tried impersonation with no
success. The service stops immediatley when attempting to run this line:

Private Declare Auto Function LogonUser Lib "advapi32.dll" (ByVal
lpszUsername As [String], _
ByVal lpszDomain As [String], ByVal lpszPassword As [String], _
ByVal dwLogonType As Integer, ByVal dwLogonProvider As Integer,
_
ByRef phToken As IntPtr) As Boolean



**As an added bonus, the file share I am trying to access is on an AS400. I
have mapped the drive and am attempting to use the pre-mapped drive. It
would
be nice to authenticate directly to the AS400 from my code, and the use the
UNC share name for the directory on the 400.
 
J

Jeff Johnson [MVP:VB]

I know that my service is running as local system and this must be causing
the problems. When I write the windowsidentity.getcurrent().name to the
event
log, it reads as NT AUTHORITY\SYSTEM. I have tried impersonation with no
success.

Is there a specific reason you can't run the service under a domain account?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top