Determine rights and privileges on Windows.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Schmiedeskamp

    Determine rights and privileges on Windows.

    Hello, I'm writing a python program (in Windows) from
    which I would like to determine whether or not either:
    1. The user has administrative access on the current
    PC.
    or (better)
    2. The currently running process has administrative
    access.

    For the first scenario, the
    win32security.L saEnumerateAcco untRight() seems to to
    be the ticket. The documentation doesn't describe
    what this function requires as parameters. It appears
    to require a PySID object and some sort of PyHANDLE
    object. I've figured out how to get the PySID object,
    but I'm not sure what type of PyHANDLE is required (or
    how to create such a thing)

    My other alternative is to check the running process
    for its authority. There appear to a number of
    functions that sound potentially logical to use,
    however I'm unable to determine which I should use.

    Has anyone done such a thing? Many thanks to anyone
    who can give me a shove down the right path.

    -Peter




    _______________ _______________ ____
    Do you Yahoo!?
    Friends. Fun. Try the all-new Yahoo! Messenger.
    Latest news coverage, email, free stock quotes, live scores and video are just the beginning. Discover more every day at Yahoo!


  • Roger Upole

    #2
    Re: Determine rights and privileges on Windows.

    The first parm to LsaEnumerateAcc ountRights is a policy handle returned
    from LsaOpenPolicy. I'll try to update the documentation.
    To list the privileges for the current process, you can use something like
    this:

    import win32process, win32security
    ph=win32process .GetCurrentProc ess()
    th = win32security.O penProcessToken (ph,win32securi ty.TOKEN_READ)
    privs=win32secu rity.GetTokenIn formation(th,wi n32security.Tok enPrivileges)
    for priv in privs:
    priv_state=''
    if priv[1]==0:
    priv_state='Dis abled'
    if priv[1]&win32security. SE_PRIVILEGE_EN ABLED:
    priv_state+=' SE_PRIVILEGE_EN ABLED'
    if priv[1]&win32security. SE_PRIVILEGE_EN ABLED_BY_DEFAUL T:
    priv_state+=' SE_PRIVILEGE_EN ABLED_BY_DEFAUL T'
    print win32security.L ookupPrivilegeN ame(None,priv[0]),priv[1],priv_state
    Note that the None parm to LookupPrivilege Name means to use the local
    machine, substitute your DC if you're in a domain.
    hth
    Roger


    "Peter Schmiedeskamp" <pschmied@yahoo .com> wrote in message
    news:mailman.36 9.1085675362.69 49.python-list@python.org ...[color=blue]
    > Hello, I'm writing a python program (in Windows) from
    > which I would like to determine whether or not either:
    > 1. The user has administrative access on the current
    > PC.
    > or (better)
    > 2. The currently running process has administrative
    > access.
    >
    > For the first scenario, the
    > win32security.L saEnumerateAcco untRight() seems to to
    > be the ticket. The documentation doesn't describe
    > what this function requires as parameters. It appears
    > to require a PySID object and some sort of PyHANDLE
    > object. I've figured out how to get the PySID object,
    > but I'm not sure what type of PyHANDLE is required (or
    > how to create such a thing)
    >
    > My other alternative is to check the running process
    > for its authority. There appear to a number of
    > functions that sound potentially logical to use,
    > however I'm unable to determine which I should use.
    >
    > Has anyone done such a thing? Many thanks to anyone
    > who can give me a shove down the right path.
    >
    > -Peter
    >
    >
    >
    >
    > _______________ _______________ ____
    > Do you Yahoo!?
    > Friends. Fun. Try the all-new Yahoo! Messenger.
    > http://messenger.yahoo.com/
    >[/color]


    Comment

    • Colin Brown

      #3
      Re: Determine rights and privileges on Windows.


      "Peter Schmiedeskamp" <pschmied@yahoo .com> wrote in message
      news:mailman.36 9.1085675362.69 49.python-list@python.org ...[color=blue]
      > Hello, I'm writing a python program (in Windows) from
      > which I would like to determine whether or not either:
      > 1. The user has administrative access on the current
      > PC.
      > or (better)
      > 2. The currently running process has administrative
      > access.[/color]

      Hi Peter

      It may be worth having a look at WMI (Google "python wmi").

      Cheers
      Colin Brown
      PyNZ



      Comment

      Working...