O'Reilly logo

Python Programming On Win32 by Mark Hammond, Andy Robinson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Obtaining the Necessary Privileges

The process of enabling new privileges is simple. We will discuss briefly the concepts and the code necessary to enable privileges, but for an in-depth discussion of privileges, refer to the Microsoft Windows NT Security documentation.

You use the win32security module to gain access to the necessary functions. The process for enabling a privilege is:

  • Obtain the current access token using the win32security.OpenAccess-Token() function.

  • Obtain the ID for the privilege using win32security.Lookup-PrivilegeValue().

  • Enable the privilege using win32security.AdjustTokenPrivileges().

When you’ve performed the operation, you need to disable the privilege again. The same process is used: win32security.AdjustTokenPrivileges() supports a flag that allows you to enable or disable the privilege. An example of this code is presented in the next section.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required