Impersonate in 2.0 Winforms

S

sloan

I've been in the asp.net world for over a year now, and now have a new
need.....non asp.net.


Is there a better way to do impersonation in 2.0 than there was in 1.1 in a
winform or console application?

Or .. said differently...

How does one impersonate a user ... in 2.0.....in a winform or console
application?



I found this:
http://mikehadlow.blogspot.com/2007/01/easy-impersonation.html


But wanted to check and make sure I'm not getting confused via old 1.1
articles.
 
A

Andy

I've been in the asp.net world for over a year now, and now have a new
need.....non asp.net.

Is there a better way to do impersonation in 2.0 than there was in 1.1 in a
winform or console application?

Or .. said differently...

How does one impersonate a user ... in 2.0.....in a winform or console
application?

I found this:http://mikehadlow.blogspot.com/2007/01/easy-impersonation.html

But wanted to check and make sure I'm not getting confused via old 1.1
articles.

Do you need to let your application logon as any user? Or are you
just trying to run your application as the current user.
 
S

sloan

I'm trying to let my application run as.... a user I setup in a config file
somewhere.for a certain portion of my code.


Its actually a WCF Host.......the issue is that I need the WindowsService
(running the Host)..to run as the normal account for windows services...but
the host has to make filecopy..to a file server, and this code/part needs to
run under an account which has read privs for hte fileserver.

Unforunately, there are thousands and thousands and thousands of files on
this server, thus granting permissions for the windowsService account isn't
possible. (One reason is that it takes a lonnnnnng time to actually set the
permissions on the folders and files of thousands and thousands of files.
The other reason is that the people controlling the file server(s) tell me
they're not going to do it)


So kinda need something like this (pseudo imaginative code)


using { impersonation="mydomain=Microsoft;user=BillGates;pwd=MsDosRules }
{
try
{
//copy files from file server to local machine
File.Copy("\\fileserver1\images\washingtonState1.jpg" ,
"C:\myfiles\washingtonState1.jpg"); // that looks like vb6 syntax (ha ha!)
}
finally
{
}

}//end using


I can give BillGates permissions to c:\myfiles\ with no problems.
I cannot give the local account (running the windows service) to
\\fileserver1\images\ unforunately.
 
W

Willy Denoyette [MVP]

sloan said:
I'm trying to let my application run as.... a user I setup in a config
file somewhere.for a certain portion of my code.


Its actually a WCF Host.......the issue is that I need the WindowsService
(running the Host)..to run as the normal account for windows
services...but the host has to make filecopy..to a file server, and this
code/part needs to run under an account which has read privs for hte
fileserver.

Unforunately, there are thousands and thousands and thousands of files on
this server, thus granting permissions for the windowsService account
isn't possible. (One reason is that it takes a lonnnnnng time to actually
set the permissions on the folders and files of thousands and thousands of
files. The other reason is that the people controlling the file server(s)
tell me they're not going to do it)


So kinda need something like this (pseudo imaginative code)


using { impersonation="mydomain=Microsoft;user=BillGates;pwd=MsDosRules }
{
try
{
//copy files from file server to local machine
File.Copy("\\fileserver1\images\washingtonState1.jpg" ,
"C:\myfiles\washingtonState1.jpg"); // that looks like vb6 syntax (ha ha!)
}
finally
{
}

}//end using


I can give BillGates permissions to c:\myfiles\ with no problems.
I cannot give the local account (running the windows service) to
\\fileserver1\images\ unforunately.


No, but you could run the service as "BillGates" without the risk of
disclosing his password like you are actually doing.

Willy.
 

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