473,418 Members | 1,965 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,418 software developers and data experts.

Impersonation - Is this possible?

I am trying to design a windows forms application (not asp.net) in C#,
and need to know if the following scenario is possible :

Once my application is running I need to be able to impersonate another
user account which will have access to a network drive that the current
user account does not have access to. Is it possible to impersonate the
required user account and map to the drive in code, enabling the current
user to view the required files?

I need to do this so that users can only view/alter files from my
application. All the files will only be accessible via a user account
(which only the admin will know), thus stopping tampering with the files
except via the application.

Can anybody can tell me if this is possible, and if it is possible some
example code would be much appreciated.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
5 1691
Steve,

You could do this, using the WindowsIdentity class, and the Impersonate
method on that class. However, you would have to store the username and
password somewhere, and that is where it gets tricky. Unless you are
obfuscating your code, it will be easy enough to find out where you are
getting that username and password from.

Check the documentation for the Impersonate method to see how to
impersonate another user.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"steve Sweales" <st***********@t-mobile.co.uk> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I am trying to design a windows forms application (not asp.net) in C#,
and need to know if the following scenario is possible :

Once my application is running I need to be able to impersonate another
user account which will have access to a network drive that the current
user account does not have access to. Is it possible to impersonate the
required user account and map to the drive in code, enabling the current
user to view the required files?

I need to do this so that users can only view/alter files from my
application. All the files will only be accessible via a user account
(which only the admin will know), thus stopping tampering with the files
except via the application.

Can anybody can tell me if this is possible, and if it is possible some
example code would be much appreciated.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #2
Even though the following article says 'asp.net' in the title, it is actually
applicable to what you want to do (impersonate a specific user).

http://support.microsoft.com/kb/306158

Specifically see the section "Impersonate a Specific User in Code", which
uses PInvokes some logon functions. There are some uphill battles to fight,
however. Like deciding where to store a username and password.

As an alternative, perhaps you could detect if the file has been tampered
by having the application stamp the file with a crytographic hash?

--
Scott
http://www.OdeToCode.com/blogs/scott/
I am trying to design a windows forms application (not asp.net) in C#,
and need to know if the following scenario is possible :

Once my application is running I need to be able to impersonate
another user account which will have access to a network drive that
the current user account does not have access to. Is it possible to
impersonate the required user account and map to the drive in code,
enabling the current user to view the required files?

I need to do this so that users can only view/alter files from my
application. All the files will only be accessible via a user account
(which only the admin will know), thus stopping tampering with the
files except via the application.

Can anybody can tell me if this is possible, and if it is possible
some example code would be much appreciated.

*** Sent via Developersdex http://www.developersdex.com *** Don't just
participate in USENET...get rewarded for it!

Nov 16 '05 #3

"steve Sweales" <st***********@t-mobile.co.uk> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I am trying to design a windows forms application (not asp.net) in C#,
and need to know if the following scenario is possible :

Once my application is running I need to be able to impersonate another
user account which will have access to a network drive that the current
user account does not have access to. Is it possible to impersonate the
required user account and map to the drive in code, enabling the current
user to view the required files?

I need to do this so that users can only view/alter files from my
application. All the files will only be accessible via a user account
(which only the admin will know), thus stopping tampering with the files
except via the application.

Can anybody can tell me if this is possible, and if it is possible some
example code would be much appreciated.


If you are running this in Windows XP I suggest you run the remote file
access code from a EnterpriseServices server type application (COM+).

So you'll have something like this:
1. Your windows forms application running as an interactive user having NO
access to the file share data.
2. A ES (COM+ server type) application running with fixed credentials and
appropriate permissions set for both launch and component access, this
application runs the code to access to the file share data.
3. As a bonus you can apply role based security at the ES application so you
can further restrict access based on finer grained usage/access rules.

Note: There is no need to map the share, use UNC paths to access the remote
files.

Willy.
Nov 16 '05 #4
Thanks for the feedback.

I have managed to impersonate a user (still haven't given any thought on
where to store the username & password yet) but have run into a problem.

Although I have managed to impersonate a user, I am unable to access the
folder on a server that the user should have access to. Does the fact
that our network uses Novell have any bearing on this? For me to map to
the folder, I am required to authenticate via Novell.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #5
See inline ***

Willy.

"steve Sweales" <st***********@t-mobile.co.uk> wrote in message
news:%2******************@TK2MSFTNGP15.phx.gbl...
Thanks for the feedback.

I have managed to impersonate a user (still haven't given any thought on
where to store the username & password yet) but have run into a problem.
*** What problem exactly, and how are you impersonating?
Please post some code.
Although I have managed to impersonate a user, I am unable to access the
folder on a server that the user should have access to. Does the fact
that our network uses Novell have any bearing on this? For me to map to
the folder, I am required to authenticate via Novell.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #6

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

Similar topics

0
by: Stephane Belzile | last post by:
Hi, I've seen a lot of people having that same problem trying to instantiate a word.application com object from an asp.net application. I have built a WEB application that is used to manage the...
1
by: CyberDigger | last post by:
I have two computers, client and server. The client is running Windows 2000 Professional and is in a workgroup, say "MyWorkgroup". The server is running Windows Server 2003 Standard Edition and...
12
by: Anil Krishnamurthy | last post by:
We have an ASP.NET application that uses COM objects through Interop. The web application requires access to network and database resources and hence, needs to impersonate a domain account. The...
2
by: Eric Veltman | last post by:
Hello everyone, Till now, I've always used IIS integrated authentication and impersonation, such that the ASP.NET code on the server is executed with the permissions of the user who is...
7
by: Bonj | last post by:
Hi I made a naff web application which uses the impersonation method in MSDN (can't find it now, but it basically revolves around creating a token by calling the LogonUser API, calling...
15
by: Patrick | last post by:
I set my web.config as follows: <authentication mode="Windows" /> <identity impersonate="true" /> Logon to my ASP.NET website as a user who can authenticate to the target database. 1) Works...
0
by: Jim Heavey | last post by:
Hello, I have been taking a swing at learning how I can use Impersonation via code and I am getting back an error code of 1314. By searching the internet, I have come to believe that this error...
0
by: h | last post by:
Hello, I am still struggling with impersonation in vb.net. I have a service that logs on to exchange but I get different results when using the "log on as" feature on the service as opposed to...
11
by: Phil | last post by:
Hi, I've currently setup a local user as described in: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnne...
0
by: Daniel Knöpfel | last post by:
Hello On our asp.net 2.0 website we impersonate every request to the identity of the user logged in. This works this way: 1. user logs in, providing username, password 2. user is authenticated...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.