Re: Impersonation code
- From: "Manfred Braun" <aa@xxxxx>
- Date: Mon, 16 May 2005 11:10:36 +0200
Hi,
I fumbled with the same thing one time and you're right. I've done this on
w2k. Additionally, the Administrator does not have the mentioned privileg by
default!
I do not know, about other OS, but I've HEARD [so I belive], this is no
longer an issue with XP/2003.
May be, that helps.
Best regards,
Manfred Braun
(Private)
Mannheim
Germany
mailto:_manfred.braun_@xxxxxxxxxxxx
(Remove the anti-spam-underscore to mail me!)
"Pramod" <pramodi@xxxxxxxxxx> wrote in message
news:u4TYp$eWFHA.3280@xxxxxxxxxxxxxxxxxxxxxxx
> Hi Tom,
>
> > Is this right? Or are both projects ASP.Net?
> Both the projects are in ASP.Net and both are executed on the same machine
> and by the same user.
>
> Again, If we add a user ( that I want to impersonate ) in the "Act as part
> of OS" then that will be hardcoding
> and that application will not execute on the other machines for the same
> user.
> Is this right ?
>
> One more thing, even I am not able to impersonate to my administrator's
> account.
>
> Thanks for your suggestions Tom,
> Regards,
> Pramod.
>
>
>
> "TomEgginger" <T.Egginger@xxxxxxxxxxx> wrote in message
> news:uDVlbt$VFHA.228@xxxxxxxxxxxxxxxxxxxxxxx
> > Hi Pramod,
> >
> > maybe I missunderstand your problem.
> >
> > - You are using this code in a WinForms Application - the Impersonation
> does
> > not succeed.
> > - Another Project - this time a WebForm Application - uses the same code
> and
> > the Impersonation is working fine
> >
> > Is this right? Or are both projects ASP.Net?
> >
> > Under what user contexts these applications are executed? I guess there
> > ought to be a difference, as this behaviour (code works fine in one
> > application but not in the other) seems to be caused by insufficent
> > rights...
> >
> > Simply check out the user contexts of both applications and compare the
> > users rights - is there a difference?
> >
> > Regards
> >
> >
> > "Pramod" <pramodi@xxxxxxxxxx> schrieb im Newsbeitrag
> > news:uh%23$Js3VFHA.2616@xxxxxxxxxxxxxxxxxxxxxxx
> > > Thanks Tom,
> > >
> > > But one thing I would like to point out is...
> > > The same code when I execute as a seperate application, it executes
> > > successfully without any error.
> > > The impersonation of the user is successfully done. But when I try the
> > > same
> > > code in my Project,
> > > ( the same lines of code ), it returns false indicating failure in
user
> > > impersonation.
> > >
> > > Similarly as you are saying, I am using Windows 2000 Server.
> > > The user I am trying to impersonate is in the Current domain & not in
my
> > > machine and is also in the SQL Server Login user's list
> > > since I want to invoke custom Query Builder in the specified user
> context.
> > > So do you mean, the user should also be in the Current computers
user's
> > > list?
> > >
> > > Thanks once again,
> > > Regards,
> > > Pramod.
> > >
> > >
> > >
> > >
> > >
> > > "TomEgginger" <T.Egginger@xxxxxxxxxxx> wrote in message
> > > news:eBr2e0zVFHA.2492@xxxxxxxxxxxxxxxxxxxxxxx
> > >> Hi,
> > >>
> > >> I have not checked your code, but as far as I know the executing user
> of
> > > the
> > >> LogonUser API needs to be granted the "Act as part of OS" right. (I
> think
> > >> this is a Windows2000 Issue only).
> > >>
> > >> Regards
> > >>
> > >> Tom
> > >>
> > >>
> > >>
> > >>
> > >>
> > >> "Pramod" <pramodi@xxxxxxxxxx> schrieb im Newsbeitrag
> > >> news:%23gEcT0sVFHA.3176@xxxxxxxxxxxxxxxxxxxxxxx
> > >> > Hi,
> > >> >
> > >> >
> > >> > I have the following Impersonation code. This code is in C# and I
> want
> > >> > to retrieve the data from the SQL server database using the
Specified
> > >> > windows username and password.
> > >> >
> > >> >
> > >> > public bool ImpersonateUser(string sUsername, string sDomain,
string
> > >> > sPassword)
> > >> > {
> > >> > bool bImpersonated = false;
> > >> > pExistingTokenHandle = new IntPtr(0);
> > >> > pExistingTokenHandle = IntPtr.Zero;
> > >> >
> > >> >
> > >> > try
> > >> > {
> > >> > const int LOGON32_PROVIDER_DEFAULT = 0;
> > >> >
> > >> >
> > >> > // create token
> > >> > //const int LOGON32_LOGON_INTERACTIVE = 2;
> > >> >
> > >> >
> > >> > const int LOGON32_LOGON_NETWORK = 3;
> > >> > //const int SecurityImpersonation = 2;
> > >> >
> > >> >
> > >> > // get handle to token
> > >> > bImpersonated = LogonUser(sUsername, sDomain, sPassword,
> > >> > LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT,
> > >> > ref pExistingTokenHandle);
> > >> > }
> > >> > catch (Exception e)
> > >> > {
> > >> > ATrace.WriteLine( ATrace.CATEGORY.ERROR,
> > >> > "SQLQueryBuilder::ImpersonateUser - " + e.Message );
> > >> > }
> > >> > return bImpersonated;
> > >> > }
> > >> >
> > >> > This code does not throw any exception but returns false.
> > >> >
> > >> > Interesting thing is, I have created a sample application similar
to
> > >> > this in ASP.Net. The same application works but not mine which is
> ther
> > >> > in project.
> > >> >
> > >> >
> > >> > So, is ther any prequisite to run that code ???
> > >> > Or is ther any project settings ???
> > >> >
> > >> >
> > >> > If you know, then plz let me know ASAP
> > >> >
> > >> >
> > >> > Thanks,
> > >> > Pramod.
> > >> >
> > >> >
> > >> >
> > >> >
> > >> >
> > >>
> > >>
> > >
> > >
> >
> >
>
>
.
- Follow-Ups:
- Re: Impersonation code
- From: Pramod
- Re: Impersonation code
- References:
- Impersonation code
- From: Pramod
- Re: Impersonation code
- From: TomEgginger
- Re: Impersonation code
- From: Pramod
- Re: Impersonation code
- From: TomEgginger
- Re: Impersonation code
- From: Pramod
- Impersonation code
- Prev by Date: Re: Impersonation code
- Next by Date: Re: Relation between Points & Pixels
- Previous by thread: Re: Impersonation code
- Next by thread: Re: Impersonation code
- Index(es):
Relevant Pages
|