Files
random_scripts/any-desk-reset-trial.bat
T
2026-04-20 14:06:57 -04:00

141 lines
4.8 KiB
Batchfile

@echo off & setlocal enableextensions
title Reset AnyDesk (patched)
reg query HKEY_USERS\S-1-5-19 >NUL 2>&1 || (echo Please run as administrator.& pause >NUL & exit /b 1)
chcp 437 >NUL
echo ============================================================
echo WARNING:
echo - This script will change your MAC. In dynamic IPs there is
echo no issues but if you have static IP and is bound to your
echo MAC you might lose internet connection.
echo - All passwords saved for AnyDesk sessions will be lost.
echo ============================================================
echo.
choice /M "Continue"
if errorlevel 2 exit /b 0
echo.
set "PD=%ALLUSERSPROFILE%\AnyDesk"
set "AD=%APPDATA%\AnyDesk"
set "AnyDesk1=%SystemDrive%\Program Files (x86)\AnyDesk\AnyDesk.exe"
set "AnyDesk2=%SystemDrive%\Program Files\AnyDesk\AnyDesk.exe"
echo [*] Stopping AnyDesk service and process...
call :stop_any
echo [*] Backing up user.conf and thumbnails to %%TEMP%%...
if exist "%AD%\user.conf" copy /y "%AD%\user.conf" "%temp%\user.conf" >NUL
rd /s /q "%temp%\ad_thumbnails" 2>NUL
if exist "%AD%\thumbnails" xcopy /c /e /h /r /y /i /k "%AD%\thumbnails" "%temp%\ad_thumbnails" >NUL
echo [*] Waiting for AnyDesk lock files to release...
set /a _i=0
:wait_locks
set "_locked="
for %%F in ("%PD%\service.conf.lock" "%PD%\system.conf.lock" "%AD%\user.conf.lock") do (
2>NUL (>>%%F echo.) || set "_locked=1"
)
if defined _locked (
set /a _i+=1
if %_i% lss 10 ( timeout /t 1 /nobreak >NUL & goto wait_locks )
)
echo [*] Wiping AnyDesk config folders...
rd /s /q "%PD%" 2>NUL
rd /s /q "%AD%" 2>NUL
echo [*] Removing AnyDesk registry fingerprint (if present)...
reg delete "HKLM\SOFTWARE\philandro Software GmbH\AnyDesk" /f >NUL 2>&1
call :randomize_mac
echo [*] Waiting 10s for network to reconnect...
timeout /t 10 /nobreak >NUL
echo [*] Starting AnyDesk to generate a new ID...
call :start_any
echo [*] Waiting for AnyDesk to obtain a new ID...
set /a _j=0
:lic
timeout /t 2 /nobreak >NUL
if exist "%PD%\system.conf" findstr /C:"ad.anynet.id=" "%PD%\system.conf" >NUL && goto got_id
set /a _j+=1
if %_j% lss 30 goto lic
echo.
echo [!] Timed out waiting for a new AnyDesk ID.
echo Check internet connectivity and firewall (*.net.anydesk.com).
echo.
pause
goto :eof
:got_id
echo [*] New ID obtained. Stopping AnyDesk to restore user settings...
call :stop_any
echo [*] Restoring user.conf and thumbnails...
if exist "%temp%\user.conf" (
if not exist "%AD%" mkdir "%AD%"
move /y "%temp%\user.conf" "%AD%\user.conf" >NUL
)
if exist "%temp%\ad_thumbnails" (
xcopy /c /e /h /r /y /i /k "%temp%\ad_thumbnails" "%AD%\thumbnails" >NUL
rd /s /q "%temp%\ad_thumbnails"
)
echo [*] Starting AnyDesk...
call :start_any
for /f "tokens=2 delims==" %%A in ('findstr /C:"ad.anynet.id=" "%PD%\system.conf"') do set "NEWID=%%A"
echo.
echo ============================================================
echo Script is finished. You can continue using AnyDesk.
echo New AnyDesk ID: %NEWID%
echo ============================================================
echo.
pause
goto :eof
:start_any
sc start AnyDesk >NUL 2>&1
if %errorlevel%==1056 goto :sa_launch
if %errorlevel%==0 goto :sa_launch
timeout /t 1 /nobreak >NUL
goto start_any
:sa_launch
if exist "%AnyDesk1%" start "" "%AnyDesk1%"
if exist "%AnyDesk2%" start "" "%AnyDesk2%"
exit /b
:randomize_mac
echo [*] Randomizing NIC MAC address...
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
"$ErrorActionPreference='Stop';" ^
"$a = Get-NetAdapter -Physical | Where-Object { $_.Status -eq 'Up' } | Select-Object -First 1;" ^
"if (-not $a) { $a = Get-NetAdapter -Physical | Select-Object -First 1 };" ^
"if (-not $a) { Write-Host '[!] No physical adapter found.'; exit 1 };" ^
"$first = '{0:X2}' -f ((Get-Random -Minimum 0 -Maximum 64) * 4 -bor 2);" ^
"$rest = -join (1..5 | ForEach-Object { '{0:X2}' -f (Get-Random -Minimum 0 -Maximum 256) });" ^
"$mac = $first + $rest;" ^
"Write-Host ('[+] Adapter: ' + $a.Name + ' New MAC: ' + ($mac -replace '(..)(?!$)','$1-'));" ^
"$base = 'HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}';" ^
"$key = Get-ChildItem $base -ErrorAction SilentlyContinue | Where-Object { (Get-ItemProperty $_.PSPath -ErrorAction SilentlyContinue).NetCfgInstanceId -eq $a.InterfaceGuid } | Select-Object -First 1;" ^
"if (-not $key) { Write-Host '[!] Registry key for adapter not found.'; exit 1 };" ^
"Set-ItemProperty -Path $key.PSPath -Name NetworkAddress -Value $mac -Type String;" ^
"Disable-NetAdapter -Name $a.Name -Confirm:$false;" ^
"Start-Sleep -Seconds 2;" ^
"Enable-NetAdapter -Name $a.Name -Confirm:$false;" ^
"Start-Sleep -Seconds 3;"
exit /b
:stop_any
sc stop AnyDesk >NUL 2>&1
if %errorlevel%==1062 goto :so_kill
if %errorlevel%==0 goto :so_kill
timeout /t 1 /nobreak >NUL
goto stop_any
:so_kill
taskkill /f /im "AnyDesk.exe" >NUL 2>&1
timeout /t 1 /nobreak >NUL
exit /b