Skip to main content

This script provides a simple way to execute a file as an administrator on Windows systems.

Project description

run-as-admin

Introduction

This script provides a simple way to execute a file as an administrator on Windows systems. It utilizes the RunAsAdmin class to handle the execution and logging of commands. By running a file as an administrator, it bypasses the usual User Account Control (UAC) prompts.

Installation

You can install run-as-admin via pip:

pip install run-as-admin

Example Usage

Install

import os
from run_as_admin import RunAsAdmin

# Define the file path of the executable
file_path = "C:\Windows\System32\cmd.exe"  # Replace this with the actual file path

# Define the path for the log file
log_file_path = os.path.join(os.getcwd(), "execution_log.log")

# Create a RunAsAdmin instance
runner = RunAsAdmin(file_path, True,log_file_path)

# Execute the file as administrator
runner.execute()

Parameters

  • file_path (str): The path to the executable file you want to run.
  • logging (bool): Set to True if you want to keep log, False otherwise.
  • log_file_path (str, optional): The path to the log file where execution details will be saved. If not specified, execution_log.log file will be created in current directory.

Reminder

If you do not want the UAC prompt to appear when executing the file, you can adjust the User Account Control settings. However, it's important to note that disabling UAC entirely for administrators can pose security risks.

Local Security Policy

In the Local Security Policy settings, navigate to:

Security Settings -> Local Policies -> Security Options

Adjust the behavior of the User Account Control: Run all administrators in Admin Approval Mode. Disabling this policy will effectively disable UAC for administrators, but it's not recommended for security reasons.

Dependencies

  • Python 3.x
  • Windows operating system

License

Copyright (c) 2024 Barno Chakraborty

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

run_as_admin-1.7.9.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

run_as_admin-1.7.9-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file run_as_admin-1.7.9.tar.gz.

File metadata

  • Download URL: run_as_admin-1.7.9.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.0

File hashes

Hashes for run_as_admin-1.7.9.tar.gz
Algorithm Hash digest
SHA256 41d4d3e4cdf1a3c30eb416ae505429e9e88fdf9093457d963e83dc4df6cedcb6
MD5 3d9b216e2348fc0519851b351c626beb
BLAKE2b-256 7634be69e7d50db91d5989792406460f16c95928a85b03e560fdf16b67e55f47

See more details on using hashes here.

File details

Details for the file run_as_admin-1.7.9-py3-none-any.whl.

File metadata

  • Download URL: run_as_admin-1.7.9-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.0

File hashes

Hashes for run_as_admin-1.7.9-py3-none-any.whl
Algorithm Hash digest
SHA256 e845ad6e78642469d053f7ff377fed486a51273034e8396be1cafd3f8120e134
MD5 106cadcd407b8b708fc1bf0eb293c8bd
BLAKE2b-256 c67dae9c0a31f8a1f9dd37aa9f4e471f8ec22efd04583fbd6641ff006b551307

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page