473,395 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Impersonation from a windows service

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.
Jul 21 '05 #1
4 15652
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/de...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...rmissions.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>
----------------------------------------------

"Leo" <no****@newsgroups.com> wrote in message
news:00****************************@phx.gbl...
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.

Jul 21 '05 #2
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/de...us/wnet/wnet/w
netaddconnection2.asp

Consuming Unmanaged DLL Functions
http://msdn.microsoft.com/library/de...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.

Jul 21 '05 #3
Tian,

Thanks for your reply. This is exactly the information I needed!

Leo.

"Tian Min Huang" <ti******@online.microsoft.com> wrote in message
news:$x**************@cpmsftngxa07.phx.gbl...
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/de...us/wnet/wnet/w netaddconnection2.asp

Consuming Unmanaged DLL Functions
http://msdn.microsoft.com/library/de...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.

Jul 21 '05 #4
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.

"John Timney (Microsoft MVP)" <ti*****@despammed.com> wrote in message
news:ON**************@TK2MSFTNGP12.phx.gbl...
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/de...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...rmissions.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>
----------------------------------------------

"Leo" <no****@newsgroups.com> wrote in message
news:00****************************@phx.gbl...
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.


Jul 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Trokey | last post by:
I am having a serious problem connecting to out-of-process COM objects in my windows service application. Whenever I try to create an instance of the COM object, a second instance of the COM server...
3
by: Chris | last post by:
Hello all, Here is my problem. I have a windows service (C#) that is supposed to move files from/to the local drive to/from a UNC share (\\domainserver\share). The service is running on a Win3k...
0
by: Johyson | last post by:
Hi, I am using a windows service which does two things 1. It calls an exe which is a screen scraping program and needs to interact with the desktop. 2. It calls an web service, which...
5
by: pberna | last post by:
Dear all, I built a Web Form application to start and stop a Windows Service remotely. I successful tested the application on Windows 2000 server + IIS. I must include the ASPNET user to the...
3
by: Doug Bailey | last post by:
I am trying to control a Windows Service via a Web Service interface. (I am developing in .NET2003) I am using the ServiceController object which allows me to read the state of the services with...
2
by: Jm | last post by:
Hi all Im writing a windows service app that accepts some remote control commands and reports to a database server. One command i would like to use is basically remote execution. When i start a...
4
by: Leo | last post by:
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...
13
by: NG | last post by:
Hi All I made a windows service in C#. Now I have a situation where I need to invoke an exe with some UI. Assuming that the computer running this service will always be logged in, can anyone...
3
by: Goran Djuranovic | last post by:
Hi all, I have a web app running on a local PC that can start and stop windows service on a remote machine, but only when I browse to it locally. If I browse to it from my other PC and try to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.