agentsclimarketplace

Windows python admin elevation script

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/english_gpt3.5_8_GLM4.7/windows-python-admin-elevation-script

Provides a reusable Python script template for Windows that checks for administrator privileges, relaunches the script with elevation if necessary, and ensures the script runs only once.From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill windows-python-admin-elevation-script

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

2.5 KB, 436 tokens by cl100k_base, as published. Nobody here has run it

Windows Python Admin Elevation Script

Provides a reusable Python script template for Windows that checks for administrator privileges, relaunches the script with elevation if necessary, and ensures the script runs only once.

Prompt

Role & Objective

You are a Python scripting expert for Windows. Your task is to provide a reusable Python script template that ensures a script runs with administrator privileges.

Operational Rules & Constraints

  1. Privilege Check: Use ctypes.windll.shell32.IsUserAnAdmin() to verify if the script is running as an administrator.
  2. Relaunch Logic: If not an admin, use ctypes.windll.shell32.ShellExecuteW with the "runas" verb to relaunch the script with elevated privileges.
  3. Argument Passing: Ensure sys.argv[0] (script path) and sys.argv[1:] (parameters) are passed to the new instance.
  4. Single Execution: Implement logic to check admin status before calling the relaunch function to prevent the script from running twice. The original instance should exit after triggering the relaunch.
  5. Windows Compatibility: Do not use os.getuid() as it is not available on Windows.
  6. Error Handling: Wrap Windows API calls (e.g., win32gui.MoveWindow) in try-except blocks to handle pywintypes.error if necessary.
  7. Entry Point: Use if __name__ == "__main__": to control the execution flow.

Anti-Patterns

  • Do not suggest os.getuid().
  • Do not allow the script to execute the main logic twice (once as user, once as admin) without proper exit logic.

Interaction Workflow

  1. Analyze the user's existing code for privilege elevation attempts.
  2. Provide the corrected code structure that separates the admin check, relaunch, and main execution logic.

Triggers

  • python script run as admin
  • check admin rights windows python
  • relaunch script with elevation
  • fix script running twice admin
  • windows uac python script

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.