Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # Filename: is_admin.py
- # Version: 1.00
- # Author: Jeoi Reqi
- """
- ADMINISTRATOR VERIFICATION TOOL:
- This script checks if the current user has Elevated Administrator Permissions.
- Elevated Administrator Permissions are required for certain operations that may affect system settings or files.
- These permissions grant the user the highest level of control over the system.
- Requirements:
- - Python 3
- - Python Interpreter (With Admin Terminal)
- - Windows OS: (Windows 7 - 11)
- Usage:
- 1. Run the script using any Python interpreter as admin or standard.
- 2. The script will determine whether it has administrative privileges.
- 3. If the script is run with administrative privileges, it will print a message confirming it.
- 4. If not, it will print a message indicating the lack of administrative privileges.
- Note:
- - This script utilizes two methods to check for administrative privileges.
- It first attempts to check the user's UID on Unix-like systems and then falls back to
- ctypes.windll.shell32.IsUserAnAdmin() on Windows systems.
- - It is important to run the script from a terminal with elevated privileges (e.g., "Run as Administrator" on Windows) to accurately detect administrative privileges.
- - This script should be run on Windows systems due to its reliance on ctypes and shell32.
- - Compatibility with other operating systems such as Unix-like systems (Linux, macOS) is possible, but may require additional packages and dependencies not listed in this script.
- """
- import ctypes
- import os
- import sys
- # Function to check if the script is running with administrative privileges
- def is_admin():
- """
- Check if the script is running with administrative privileges.
- Returns:
- bool: True if the script is running with administrative privileges, False otherwise.
- """
- try:
- # Check if the process is running with elevated privileges on Unix-like systems
- return os.getuid() == 0
- except AttributeError:
- try:
- # Attempt to check administrative privileges on Windows systems using ctypes
- return ctypes.windll.shell32.IsUserAnAdmin() != 0
- except Exception:
- return False
- if __name__ == "__main__":
- if is_admin():
- print("The script is being run with administrative privileges.")
- else:
- print("The script is not being run with administrative privileges.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement