win32security.LogonUser not working

dsavitsk dsavitsk at e-coli.net
Sun Sep 15 18:51:05 CEST 2002


I have gone so far as to assign every possible right in dir(ntsecuritycon),
but i am still getting the same error. I have also assigned nearly everyone
and every thing on my network the right to act as the os. any ideas?

-d


"dsavitsk" <dsavitsk at e-coli.net> wrote in message
news:L9Pg9.8440$yt3.4474038 at newssrv26.news.prodigy.com...
> should have mentioned
> python:   2.1.3
> win32all: 145
> win2k:    sp2
>
>
> "dsavitsk" <dsavitsk at e-coli.net> wrote in message
> news:x6Pg9.8439$yt3.4473830 at newssrv26.news.prodigy.com...
> > I am trying to run code as another user. I copied the code below from
> ASPN,
> > so it would seem that someone has gotten this to work. I keep getting
the
> > error
> >
> > pywintypes.api_error (1314, 'LogonUser', 'A required privilege is not
held
> > by the client.')
> >
> > Google has revealed that others gave had the same problem.  does anyone
> know
> > a solution, or even a different way to do this?
> >
> > -doug
> >
> > link to the original of code below
> >
>
http://www.google.com/search?q=cache:Jnbt2XVyGfUC:aspn.activestate.com/ASPN/
> >
>
Python/Reference/Products/ActivePython/PythonWin32Extensions/Windows_NT_Secu
> >
>
rity_.2d.2d_Impersonation.html+self.handel%3Dwin32security.LogonUser&hl=en&i
> > e=UTF-8
> >
> > ---------------------------------------------
> > import win32security
> > import win32con
> > import win32api
> > import sys
> >
> >
> > class Impersonate:
> >
> >     def __init__(self):
> >         self.domain   = '.'
> >         self.login    = 'myusername'
> >         self.password = '**********'
> >
> >     def logon(self):
> >         self.handel=win32security.LogonUser(self.login,
> >                                             self.domain,
> >                                             self.password,
> >
> > win32con.LOGON32_LOGON_INTERACTIVE,
> >
> > win32con.LOGON32_PROVIDER_DEFAULT
> >                                             )
> >         win32security.ImpersonateLoggedOnUser(self.handel)
> >
> >     def logoff(self):
> >         win32security.RevertToSelf() #terminates impersonation
> >         self.handel.Close() #guarantees cleanup
> >
> >
> >
> >
> > if __name__ == '__main__':
> >     a=Impersonate()
> >     try:
> >         a.logon() #become the user
> >         print win32api.GetUserName() #show you're someone else
> >         a.logoff() #return to normal
> >     except:
> >         print sys.exc_type , sys.exc_value
> >
> >
>
>





More information about the Python-list mailing list