-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWinOpti.bat
More file actions
52 lines (43 loc) · 1.71 KB
/
WinOpti.bat
File metadata and controls
52 lines (43 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
@echo off
setlocal EnableExtensions
:: ============================================================================
:: WinOpti.bat - Final, Optimized & Working Version
::
:: This version maintains the exact script structure proven to work in the
:: restrictive environment, while incorporating clear error messages and
:: enhanced security by removing argument forwarding.
:: ============================================================================
:: --- Configuration ---
set "SCRIPT_PATH=%~dp0"
set "SCRIPT_NAME=%~dpn0.ps1"
set "POWERSHELL=powershell.exe"
:: --- Pre-checks ---
:: 1. Change to script directory
cd /d "%SCRIPT_PATH%" || (
echo [ERROR] Falha ao mudar para o diretorio do script.
pause
exit /b 1
)
:: 2. Check if PowerShell executable exists
where %POWERSHELL% >nul 2>nul || (
echo [ERROR] Executavel do PowerShell nao encontrado no PATH.
pause
exit /b 1
)
:: 3. Check if the target PowerShell script exists
if not exist "%SCRIPT_NAME%" (
echo [ERROR] O script alvo '%SCRIPT_NAME%' nao foi encontrado.
pause
exit /b 1
)
:: --- Argument Preparation & Elevation (Security Hardened) ---
:: Argument forwarding (%*) has been removed to prevent potential injection vulnerabilities.
set "ELEVATED_ARGS=-NoProfile -ExecutionPolicy Bypass -File \"%SCRIPT_NAME%\""
:: Execute PowerShell to trigger Start-Process with elevation (Original Multi-line Syntax)
%POWERSHELL% -NoProfile -ExecutionPolicy Bypass -Command ^
"Start-Process -FilePath '%POWERSHELL%' -ArgumentList '%ELEVATED_ARGS%' -Verb RunAs" || (
echo [ERROR] Falha ao enviar o pedido de elevacao. O usuario pode ter cancelado o UAC.
pause
exit /b 1
)
:: --- Completion