@setlocal DisableDelayedExpansion @echo off cls title Reiniciando y borrando set Unattended= set _args= set _elev= set Task= set "_arg1=%~1" if not defined _arg1 goto :NoProgArgs set "_args=%~1" set "_arg2=%~2" if defined _arg2 set "_args=%~1 %~2" for %%A in (%_args%) do ( if /i "%%A"=="-el" set _elev=1 if /i "%%A"=="/u" set Unattended=1 if /i "%%A"=="Task" set Task=1&set Unattended=1) :NoProgArgs for /f "tokens=6 delims=[]. " %%G in ('ver') do set winbuild=%%G set "_psc=powershell" set "nul=1>nul 2>nul" set "EchoRed=%_psc% write-host -back Black -fore Red" set "EchoGreen=%_psc% write-host -back Black -fore Green" set "EchoBlack=%_psc% write-host -back Black -fore Black" set "ELine=echo: & %EchoRed% ==== ERROR ==== &echo:" ::======================================================================================================================================== for %%i in (powershell.exe) do if "%%~$path:i"=="" ( echo: &echo ==== ERROR ==== &echo: echo Powershell is not installed in the system. echo Aborting... goto Done ) ::======================================================================================================================================== :: Fix for the special characters limitation in path name :: Written by @abbodi1406 set "_batf=%~f0" set "_vbsf=%temp%\admin.vbs" set _PSarg="""%~f0""" -el if defined _args set _PSarg="""%~f0""" -el """%_args%""" setlocal EnableDelayedExpansion :: Elevate script as admin and pass arguments and preventing loop %nul% reg query HKU\S-1-5-19 && ( goto :Passed ) || ( if defined _elev goto :E_Admin ) ( echo Set strArg=WScript.Arguments.Named echo Set strRdlproc = CreateObject^("WScript.Shell"^).Exec^("rundll32 kernel32,Sleep"^) echo With GetObject^("winmgmts:\\.\root\CIMV2:Win32_Process.Handle='" ^& strRdlproc.ProcessId ^& "'"^) echo With GetObject^("winmgmts:\\.\root\CIMV2:Win32_Process.Handle='" ^& .ParentProcessId ^& "'"^) echo If InStr ^(.CommandLine, WScript.ScriptName^) ^<^> 0 Then echo strLine = Mid^(.CommandLine, InStr^(.CommandLine , "/File:"^) + Len^(strArg^("File"^)^) + 8^) echo End If echo End With echo .Terminate echo End With echo CreateObject^("Shell.Application"^).ShellExecute "cmd.exe", "/c " ^& chr^(34^) ^& chr^(34^) ^& strArg^("File"^) ^& chr^(34^) ^& strLine ^& chr^(34^), "", "runas", 1 )>"!_vbsf!" (%nul% cscript //NoLogo "!_vbsf!" /File:"!_batf!" -el "!_args!") && ( del /f /q "!_vbsf!" exit /b ) || ( del /f /q "!_vbsf!" %nul% %_psc% "start cmd.exe -arg '/c \"!_PSarg:'=''!\"' -verb runas" && ( exit /b ) || ( goto :E_Admin ) ) exit /b :E_Admin %ELine% if "!_batf!"=="%ProgramData%\Online_KMS_Activation\Activate.cmd" ( echo Unable to elevate the script as admin. echo Try to manually run the file as admin - "%ProgramData%\Online_KMS_Activation\Activate.cmd" ) else ( echo This script require administrator privileges. echo To do so, right click on this script and select 'Run as administrator'. ) :Done %EchoRed% Hubo algĂșn error al elevar el programa.... %EchoRed% Presione una tecla para continuar. Pause >Null Exit /b :Passed net stop w3svc Echo Borrando logs. %EchoBlack% . del c:\Temp\*.* /q del d:\servidor\AGES\log\*.* /q del d:\servidor\AGES_Testing\log\*.* /q net start w3svc %EchoGreen% Reiniciado! Presione una tecla para continuar. Pause >Null exit /b