SHARE
    TWEET
    J2897

    Cygwin Remover v1.5 - BETA

    Mar 9th, 2016
    1,262
    0
    Never
    Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
    Batch 4.23 KB | None | 0 0
    1. :: Released under the GNU General Public License version 3 by J2897.
    2. @echo OFF
    3. setlocal
    4. title Cygwin Remover
    5. cls
    6. :: Cygwin's POSIX permissions often confuse people whom then try to adjust
    7. :: permissions from Windows - which can be brutal for delicate, little Cygwin.
    8. :: Cygwin's permissions are only meant to be configured from within Cygwin. So
    9. :: if you've accidentally messed up Cygwin's permissions, this may help you to
    10. :: remove Cygwin ready for a fresh, warm and cosy, reinstall.
    11. :: Inspired by...
    12. :: http://superuser.com/questions/167219/how-to-completely-uninstall-remove-cygwin-from-windows-7
    13. set "TAB= "
    14. set "CYGUSER=cyg_server"
    15. set "ERRORS=0"
    16. ver | find "Version 6." >nul
    17. if %ERRORLEVEL% EQU 0 (
    18. set "OS_VERSION=Windows 7"
    19. goto :Checks
    20. )
    21. ver | find "Version 5." >nul
    22. if %ERRORLEVEL% EQU 0 (
    23. set "OS_VERSION=Windows XP"
    24. )
    25. :Checks
    26. if not defined OS_VERSION (
    27. echo Unsupported operating system.
    28. echo.
    29. goto :End
    30. )
    31. if "%OS_VERSION%"=="Windows 7" (
    32. REM Do OPENFILES to check for administrative privileges
    33. openfiles >nul
    34. if errorlevel 1 (
    35. color cf
    36. echo Right-click on this file and select 'Run as administrator'.
    37. pause
    38. color
    39. exit /b 1
    40. )
    41. )
    42. if exist "%SYSTEMDRIVE%\cygwin" (set "MCF=%SYSTEMDRIVE%\cygwin")
    43. if exist "%SYSTEMDRIVE%\cygwin64" (set "MCF=%SYSTEMDRIVE%\cygwin64")
    44. if not defined MCF (
    45. echo Cygwin folder doesn't exist.
    46. goto :end
    47. )
    48. net user | find "%CYGUSER%" >nul
    49. if %ERRORLEVEL% NEQ 0 (
    50. echo Unable to proceed. The user %CYGUSER% doesn't exist.
    51. goto :end
    52. )
    53. if exist "%MCF%\home\%USERNAME%\.bashrc" (
    54. echo WTF^? Dude, I ain't destroying your ".bashrc" file:
    55. echo %MCF%\home\%USERNAME%\.bashrc
    56. explorer /select,"%MCF%\home\%USERNAME%\.bashrc"
    57. goto :end
    58. )
    59. set "DELSERV=0"
    60. echo Stopping and deleting services created by the user "%CYGUSER%"...
    61. for /F %%A in ('wmic service get name^, StartName ^|find ".\%CYGUSER%"') do (
    62. net stop "%%A" && sc delete "%%A"
    63. if %ERRORLEVEL% NEQ 0 (set "DELSERV=1")
    64. )
    65. if %DELSERV% EQU 1 (set /a "ERRORS+=1" & echo There was a problem.)
    66. echo Taking ownership of the Main Cygwin Folder...
    67. takeown /F "%MCF%" /R /D Y >nul
    68. if %ERRORLEVEL% NEQ 0 (
    69. set /a "ERRORS+=1"
    70. echo There was a problem.
    71. ) else (
    72. echo Done.
    73. )
    74. echo Resetting permissions...
    75. if "%OS_VERSION%"=="Windows XP" (
    76. icacls "%MCF%" /reset /T /C /Q >nul 2>&1
    77. ) else (
    78. icacls "%MCF%" /reset /T /C /L /Q
    79. )
    80. if %ERRORLEVEL% NEQ 0 (set /a "ERRORS+=1" & echo There was a problem.)
    81. echo Removing the Main Cygwin Folder...
    82. RD /S /Q "%MCF%"
    83. if %ERRORLEVEL% NEQ 0 (set /a "ERRORS+=1" & echo There was a problem.)
    84. echo Deleting users...
    85. net user | find "%CYGUSER%" >nul
    86. if %ERRORLEVEL% EQU 0 (
    87. net user %CYGUSER% /delete
    88. )
    89. net user | find "sshd" >nul
    90. if %ERRORLEVEL% EQU 0 (
    91. net user sshd /delete
    92. )
    93. if "%OS_VERSION%"=="Windows XP" (
    94. set "CUF=%SYSTEMDRIVE%\Documents and Settings\%CYGUSER%"
    95. ) else (
    96. set "CUF=%SYSTEMDRIVE%\Users\%CYGUSER%"
    97. )
    98. echo Taking ownership of the Cygwin User Folder...
    99. takeown /F "%CUF%" /R /D Y >nul
    100. if %ERRORLEVEL% NEQ 0 (
    101. set /a "ERRORS+=1"
    102. echo There was a problem.
    103. ) else (
    104. echo Done.
    105. )
    106. :: I think the errorlevel of "if" will be returned instead of "icacls". 'Needs testing.
    107. echo Resetting permissions...
    108. if "%OS_VERSION%"=="Windows XP" (
    109. icacls "%CUF%" /reset /T /C /Q >nul 2>&1
    110. ) else (
    111. icacls "%CUF%" /reset /T /C /L /Q
    112. )
    113. if %ERRORLEVEL% NEQ 0 (set /a "ERRORS+=1" & echo There was a problem.)
    114. echo Removing the Cygwin User Folder...
    115. RD /S /Q "%CUF%"
    116. if %ERRORLEVEL% NEQ 0 (set /a "ERRORS+=1" & echo There was a problem.)
    117. echo Deleting firewall entry...
    118. if exist "%SYSTEMDRIVE%\Program Files (x86)" (
    119. netsh advfirewall firewall delete rule name="OpenSSH"
    120. ) else (
    121. netsh firewall delete allowedprogram "%SYSTEMDRIVE%\cygwin\usr\sbin\sshd.exe"
    122. )
    123. echo Cleaning registry...
    124. reg delete HKCU\Software\Cygwin /f >nul 2>&1
    125. reg delete HKLM\Software\Cygwin /f >nul 2>&1
    126. echo.
    127. if %ERRORS% EQU 0 (
    128. echo Cygwin was removed absolutely perfectly^! ^:^)
    129. ) else (
    130. echo The removal of Cygwin didn't go so well. There were at least %ERRORS% problem^(s^).
    131. )
    132. if exist "%USERPROFILE%\.bashrc" (
    133. echo.
    134. echo Don't forget about your ".bashrc" file:
    135. echo %USERPROFILE%\.bashrc
    136. )
    137. :end
    138. endlocal
    139. echo.
    140. pause
    Advertisement
    Add Comment
    Please, Sign In to add comment
    Public Pastes
    We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
    Not a member of Pastebin yet?
    Sign Up, it unlocks many cool features!

    AltStyle によって変換されたページ (->オリジナル) /