Re: Impersonation code



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::ImpersonateU­­ser - " + 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.
> > >> >
> > >> >
> > >> >
> > >> >
> > >> >
> > >>
> > >>
> > >
> > >
> >
> >
>
>


.



Relevant Pages

  • Re: Impersonation code
    ... and that application will not execute on the other machines for the same ... Regards, ... > - You are using this code in a WinForms Application - the Impersonation ... > Simply check out the user contexts of both applications and compare the ...
    (microsoft.public.dotnet.faqs)
  • Re: Impersonation code
    ... > Best regards, ... >> Pramod. ... >>> the Impersonation is working fine ... >>> Simply check out the user contexts of both applications and compare ...
    (microsoft.public.dotnet.faqs)
  • Re: Impersonation code
    ... The same code when I execute as a seperate application, ... The impersonation of the user is successfully done. ... >> to retrieve the data from the SQL server database using the Specified ... The same application works but not mine which is ther ...
    (microsoft.public.dotnet.faqs)
  • Impersonation not working with WebClient...
    ... I have an ASP page on SERVERA which calls a third party COM Component ... database and execute the search. ... I initially thought it might have something to do with the TEST server ... Then I thought maybe the impersonation wasn't working, ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: How to make and executable mdb file
    ... Note that MDE is distinct from runtime even though they can have same ... MDB file running on runtime can't be altered but can be by running a ... and deny all permissions except to execute the object to the public. ...
    (microsoft.public.access.reports)