Even the best automation scripts are useless if they are tedious to launch. Right now, running our Python security audit tool requires opening CMD manually, navigating directories, and typing commands. For an IT admin managing multiple machines, this process wastes valuable time.
We can solve this problem completely by wrapping our Python engine inside a native Windows Batch (.bat) script. With a simple double-click, this automation wrapper forces the script to elevate itself to Administrator mode, verifies system paths, and executes the scan seamlessly.
Here is the complete HTML code deployment guide to build your one-click helpdesk launcher.
📥 The One-Click Windows Batch Script Wrapper
Create a new text file inside the exact same folder where your security_audit.py file lives. Name this new file run_audit.bat. Right-click it, select edit, and paste the following code:
@echo off
:: Force the script to request administrative privileges automatically
net session >nul 2>&1
if %errorLevel% neq 0 (
echo [!] Requesting Admin Privileges...
powershell -Command "Start-Process -FilePath '%0' -Verb RunAs"
exit /b
)
:: Navigate to the directory where this batch file is currently running
cd /d "%~dp0"
echo [*] Launching Ayouli IT Tech Security Audit Engine...
echo ----------------------------------------------------
:: Check if Python is installed in the system environment variables
where python >nul 2>&1
if %errorLevel% neq 0 (
echo [ERROR] Python was not found on this machine!
echo Please install Python and check 'Add to PATH'.
pause
exit /b
)
:: Execute the target Python script and keep the window open afterward
python security_audit.py
echo ----------------------------------------------------
echo [*] Operation Finished. You can close this window.
pause
🛠️ How It Works Behind the Scenes
- Self-Elevation: The
net sessionline checks for root access. If it fails, it secretly calls PowerShell to re-launch itself via an official Windows User Account Control (UAC) admin prompt. - Directory Locking: Windows Batch files often default to running inside
C:\Windows\System32when run as admin. Thecd /d "%~dp0"command explicitly forces the command line back into the folder where your script lives. - Environment Safety Check: The script checks if
pythonexists before launching, preventing confusing windows crash bugs if dependencies are missing.
🚀 How to Run the Tool
- Ensure
security_audit.pyandrun_audit.batare sitting in the same directory. - Double-click on
run_audit.bat. - Accept the Windows UAC permission dialog.
- The console will instantly display your live audit data and generate your
security_audit_report.txtfile in the background.
No comments:
Post a Comment