Home All Groups Group Topic Archive Search About

Run code under diffrent user

Author
18 Jan 2006 11:39 PM
Philip Wagenaar
I have some code that I want to run under another user. I know his password.

I want the vb.net code in my program to strart under under that user and not
start an external program.

This because the application will run as a windows service and I cannot
start an exe from a service that runs under user account with administrator
rights. The service cannot run under localsystem because it also havs to
create users and add them to administrators group.

Author
18 Jan 2006 11:48 PM
Herfried K. Wagner [MVP]
"Philip Wagenaar" <philip.wagenaar@online.nospam> schrieb:
>I have some code that I want to run under another user. I know his
>password.

Impersonation:

..NET 1.0/1.1:

<URL:http://www.codeproject.com/csharp/RunAs.asp>
<URL:http://groups.google.com/group/microsoft.public.dotnet.framework.adonet/msg/6a4c72eca2f437a4>

..NET 2.0:

<URL:http://msdn2.microsoft.com/en-us/library/bbthyk23(en-US,VS.80).aspx>

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
18 Jan 2006 11:56 PM
Philip Wagenaar
this requires a filename of the application you want to start.

I do not want to start another application, I want part of my code to run
under a diffrent useraccount. This is because of the application is running
as a windows service.

Show quoteHide quote
"Herfried K. Wagner [MVP]" wrote:

> "Philip Wagenaar" <philip.wagenaar@online.nospam> schrieb:
> >I have some code that I want to run under another user. I know his
> >password.
>
> Impersonation:
>
> ..NET 1.0/1.1:
>
> <URL:http://www.codeproject.com/csharp/RunAs.asp>
> <URL:http://groups.google.com/group/microsoft.public.dotnet.framework.adonet/msg/6a4c72eca2f437a4>
>
> ..NET 2.0:
>
> <URL:http://msdn2.microsoft.com/en-us/library/bbthyk23(en-US,VS.80).aspx>
>
> --
>  M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
>  V B   <URL:http://classicvb.org/petition/>
>
>
Author
19 Jan 2006 6:35 AM
Peter Huang" [MSFT]
Hi Philip,

From you description, I understand that you want to run some codes in your
VB.NET Windows Service application under another user account.

If I misunderstood, please feel free to let me know.

Based on my research, we can call the LogonUser API to get the user's
security token. In Whidbey, the WindowsImpersonationContext will use the
security token to set the current thread under that user's security context.

Here are some links for your reference.
How to Impersonate
http://blogs.msdn.com/shawnfa/archive/2005/03/21/400088.aspx

How To: Use Impersonation and Delegation in ASP.NET 2.0
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag2/html
/paght000023.asp

Please try this and let me know the result.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.