@echo off
REM ===========================================================================
REM  D&D Docket - remove this computer's registration
REM
REM  Undoes what INSTALL.cmd registered with Windows:
REM
REM    - the task that starts the docket at boot
REM    - the task that backs up at 15:00
REM    - the firewall rule
REM    - the two desktop icons
REM
REM  It does NOT touch the firm's register, its documents, its backups, or
REM  this folder. Nothing here deletes a single trademark. To move the docket
REM  to another computer, run this one, then MAKE-TRANSFER-COPY.cmd.
REM ===========================================================================
setlocal
cd /d "%~dp0"
title D^&D Docket - Remove registration

net session >nul 2>nul
if errorlevel 1 (
  echo.
  echo   This needs administrator rights. Asking Windows for them - say Yes.
  echo.
  powershell -NoProfile -Command "Start-Process -FilePath '%~f0' -Verb RunAs" >nul 2>nul
  exit /b 0
)

echo.
echo   =====================================================================
echo    Removing this computer's D^&D Docket registration
echo   =====================================================================
echo.
echo    Your register, documents and backups are NOT touched. Only the
echo    Windows entries that start and back up the docket are removed.
echo.
set /p "YES=   Go ahead? [Y/N]: "
if /i not "%YES%"=="Y" (
  echo.
  echo    Nothing was changed.
  echo.
  pause
  exit /b 0
)

echo.
echo     - stopping the docket
schtasks /end /tn "D&D Docket" >nul 2>nul
echo     - removing the startup task
schtasks /delete /tn "D&D Docket" /f >nul 2>nul
echo     - removing the backup task
schtasks /delete /tn "D&D Docket backup" /f >nul 2>nul
echo     - removing the firewall rule
powershell -NoProfile -Command "Remove-NetFirewallRule -DisplayName 'D&D Docket' -ErrorAction SilentlyContinue" >nul 2>nul
echo     - removing the desktop icons
powershell -NoProfile -Command ^
  "$d=[Environment]::GetFolderPath('Desktop');" ^
  "foreach ($n in @('D&D Docket','D&D Invoices')) { Remove-Item (Join-Path $d ($n+'.lnk')) -ErrorAction SilentlyContinue }" >nul 2>nul

REM  Sleep is left alone on purpose. Somebody may want this computer to sleep
REM  again, and somebody may not - it is a decision about the machine, not
REM  about the docket, and silently changing it back would be presumptuous.
echo.
echo   =====================================================================
echo    Removed.
echo   =====================================================================
echo.
echo    Still here, untouched:
echo        data\            the register, the documents, the audit trail
echo        backups\         every backup taken
echo        this folder      the program itself
echo.
echo    This computer no longer serves the docket. Nobody can reach it until
echo    INSTALL.cmd is run here again, or on another computer.
echo.
echo    Note: this computer was set not to sleep. That has been left as it is,
echo    because it is a decision about the machine rather than about the
echo    docket. Change it in Settings - System - Power if you want it back.
echo.
pause
