473,395 Members | 1,556 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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.LsaEnumerateAccountRight() 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/

Jul 18 '05 #1
2 2902
The first parm to LsaEnumerateAccountRights 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.GetCurrentProcess()
th = win32security.OpenProcessToken(ph,win32security.TO KEN_READ)
privs=win32security.GetTokenInformation(th,win32se curity.TokenPrivileges)
for priv in privs:
priv_state=''
if priv[1]==0:
priv_state='Disabled'
if priv[1]&win32security.SE_PRIVILEGE_ENABLED:
priv_state+=' SE_PRIVILEGE_ENABLED'
if priv[1]&win32security.SE_PRIVILEGE_ENABLED_BY_DEFAULT:
priv_state+=' SE_PRIVILEGE_ENABLED_BY_DEFAULT'
print win32security.LookupPrivilegeName(None,priv[0]),priv[1],priv_state
Note that the None parm to LookupPrivilegeName means to use the local
machine, substitute your DC if you're in a domain.
hth
Roger
"Peter Schmiedeskamp" <ps******@yahoo.com> wrote in message
news:ma*************************************@pytho n.org...
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.LsaEnumerateAccountRight() 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/

Jul 18 '05 #2

"Peter Schmiedeskamp" <ps******@yahoo.com> wrote in message
news:ma*************************************@pytho n.org...
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.


Hi Peter

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

Cheers
Colin Brown
PyNZ

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: could ildg | last post by:
I want to check if a folder named "foldername" is empty. I use os.listdir(foldername)== to do this, but it will be very slow if the folder has a lot of sub-files. Is there any efficient ways to do...
4
by: lauren quantrell | last post by:
Is there a way to determine if the current Windows user has local admin rights on the client machine, using VBA code? Thanks, lq
0
by: shefali | last post by:
Hi, I need to use an HTTPHandler to create and write files. I wanted to create the file in the directory that has this handler, and other handlers. For me, this directory is:...
3
by: Danny Miller | last post by:
Hi there, I've got a web app that uses impersonation and makes calls to a SQL Server backend. I'd like to be able to automate the setting of database security for the web app upon deployment....
2
by: gary.comstock | last post by:
We have setup 4 NT groups - Executive, Manager, Employee and Contractor. The premise is that an Executive has all of the privileges of Itself plus Manager plus Employee plus Contractor while an...
5
by: =?Utf-8?B?bGpsZXZlbmQy?= | last post by:
Is there any way to do the following: 1. Determine whether ClearType is enabled by the system (under Display Properties - Effects in WinXP). 2. Determine whether a font supports ClearType. ...
1
by: ringoschplingo | last post by:
Hi, (sorry this is a long one) I have MSSQL 2000 (version 8.00.2187) installed on Windows Server 2K3, nothing 'special' has been done to either of these servers as far as configuration goes. ...
3
by: Koliber (js) | last post by:
sorry for my bad english when I fire up (from my c# code) a standard "file - save as " dialog, and when chosen location is a shered local network directory, where I do have rights to create...
0
by: EricBlair | last post by:
Hello, I wrote a windows service that is supposed to start an interactive GUI app. I realize a service will not readily do this so I've pieced together the code below to bypass that. However, the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.