Impersonation from a windows service

  • Thread starter Thread starter Leo
  • Start date Start date
L

Leo

Hi,

I Need to access some files in a directory on server B
from a windows service (written in VB.NET) running on
server A (localsystem account).

How can I impersonate a user with sufficient rights on
server B from within the service running on server A so I
can access the files on server B?

Thanks in advance, Leo.
 
You will probably need to start with the networkcredentials classes and work
out what you need to pass from there
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemnetnetworkcredentialclasstopic.asp

A better (quicker) approach would to install your service to run under a
designated account that has the correct permissions already to connect to
remote drives etc.

and this is a neccesary read........
http://www.ondotnet.com/pub/a/dotnet/2003/02/18/permissions.html

--
Regards

John Timney (Microsoft ASP.NET MVP)
----------------------------------------------
<shameless_author_plug>
Professional .NET for Java Developers with C#
ISBN:1-861007-91-4
Professional Windows Forms
ISBN: 1861005547
Professional JSP 2nd Edition
ISBN: 1861004958
Professional JSP
ISBN: 1861003625
Beginning JSP Web Development
ISBN: 1861002092
</shameless_author_plug>
 
Hi Leo,

Thanks for your post. I suggest that you can call WNetAddConnection2() API
to connect the directory on remote server. For .NET managed application,
you need to use P/Invoke to call unmanaged API. Please refer to the
following KB articles:

WNetAddConnection2
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wnet/wnet/w
netaddconnection2.asp

Consuming Unmanaged DLL Functions
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconconsumingunmanageddllfunctions.asp?frame=true

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Thanks for your reply John,

I need to connect to a UNIX server, so the account is not part of the server
(or domain) that I'm connecting from. I got some useful links from another
reply (Tian).

Leo.
 
Back
Top