anchor.diff:  rem Uninstall Cygwin.
   rem See http://cygwin.com/faq/faq-nochunks.html#faq.setup.uninstall-all
   rem
  -rem Copyright (c) 2012 Tom Schutter
  +rem This would be much easier to implement as a shell script, but
  +rem sometimes the whole point of uninstalling Cygwin is that it is in a
  +rem non-working state.
  +rem
  +rem Copyright (c) 2012-2013 Tom Schutter
   rem All rights reserved.
   rem
   rem Redistribution and use in source and binary forms, with or without
  
positive.code: 
  
  :uninstall_lsa
      echo %_PREFIX% Checking if cyglsa is hooked into OS
      reg query HKLM\SYSTEM\CurrentControlSet\Control\Lsa /v "Authentication Packages" | findstr cyglsa > NUL:
      if %ERRORLEVEL% NEQ 0 exit /b 0
  
      echo %_PREFIX% Checking for sane Authentication Packages value
      for /f "usebackq tokens=4-9" %%f in (`reg query HKLM\SYSTEM\CurrentControlSet\Control\Lsa /v "Authentication Packages"`) do set _AP_VALUE=%%f
      set _AP_VALUEQ=%_AP_VALUE:\0=?%
      for /f "usebackq delims=? tokens=1,2,3" %%f in ('%_AP_VALUEQ%') do (
  
negative.code: goto :eof
  
  
  :is_cygwin_user
      rem Return 1 if the %1 user appears to have been created by Cygwin, 0 otherwise.
      set _HOMEDIR=
      for /f "usebackq tokens=3*" %%d in (`net user %1 2^>NUL ^| findstr /c:"Home\ directory" 2^>NUL`) do set _HOMEDIR=%%d
      if "%_HOMEDIR%" == "" exit /b 0
      echo %_HOMEDIR% | findstr /lib "%_ROOTDIR%" >NUL && exit /b 1
  exit /b 0
  
  
  :remove_local_user
      :remove_local_user_ask
          set /p _ANSWER=%_PREFIX% Remove local Cygwin user "%1" (y/n)?
          if "%_ANSWER%" == "n" goto :eof
          if "%_ANSWER%" == "N" goto :eof
          if "%_ANSWER%" == "y" goto :remove_local_user_ask_done
          if "%_ANSWER%" == "Y" goto :remove_local_user_ask_done
          goto :remove_local_user_ask
      :remove_local_user_ask_done
      echo %_PREFIX% Removing local user "%1"
      net user %1 /remove
  goto :eof
  
  
  :remove_local_cygwin_users
      echo %_PREFIX% Searching for users created by Cygwin...
      for /f "usebackq tokens=*" %%l in (`net user`) do (
          rem %%l is a line of output from "net user", split it into words.
          for %%u in (%%l) do (
              rem Note that many of these "users" are just cruft from the "net user" command.
              call :is_cygwin_user %%u || call :remove_local_user %%u
          )
      )
  goto :eof
  
  
  :main
      call :check_rootdir ||exit /b 1
      call :check_admin ||exit /b 1
      call :remove_local_cygwin_users
      call :uninstall_lsa ||exit /b 1
      call :stop_services
      call :check_for_cygwin_proc ||exit /b 1
  