无忧启动论坛

标题: 有懂批处理的大佬吗,有个脚本需要键盘输入Y能帮我改下吗 [打印本页]

作者: 黑色de郁金香    时间: 2020-2-12 12:16
标题: 有懂批处理的大佬吗,有个脚本需要键盘输入Y能帮我改下吗
我找到一个卸载onedrive的批处理,里面需要输入以下Y进行确认,我想把这个弄成启动之后就自动执行的,有大佬懂批处理语言吗?
UninstallOneDrive.zip (1.93 KB, 下载次数: 15)

作者: chishingchan    时间: 2020-2-12 12:32
(免下载!)附件的源码:
  1. @rem OneDrive Complete uninstaller batch process for Windows 10.
  2. @rem Run as administrator to completely delete all OneDrive components and files.
  3. @rem Written by TERRA Operative - 2016/08/31. V1.2
  4. @rem Feel free to distribute freely as long as you leave this entire file unchanged and intact,
  5. @rem and if you do make changes and adaptions, don't be a dick about attributing where due.
  6. @rem And most importantly, peace out and keep it real.

  7. @echo OFF

  8. @REM Set variables for coloured text
  9. SETLOCAL EnableDelayedExpansion
  10. for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do     rem"') do (
  11.   set "DEL=%%a"
  12. )

  13.    echo ------Windows 10 OneDrive Uninstaller V1.2------
  14.    echo.
  15.    
  16. @rem This code block detects if the script is being running with admin privileges. If it isn't it pauses and then quits.
  17. NET SESSION >nul 2>&1
  18. IF %ERRORLEVEL% EQU 0 (


  19.    echo        Administrator Privileges Detected!
  20.    echo.
  21. ) ELSE (

  22.    echo.
  23.    call :colorEcho 0C "########### ERROR - ADMINISTRATOR PRIVILEGES REQUIRED #############"
  24.    echo.
  25.    call :colorEcho 0C "#                                                                 #"
  26.    echo.
  27.    call :colorEcho 0C "#"
  28.    call :colorEcho 07 "    This script must be run as administrator to work properly."
  29.    call :colorEcho 0C "    #"
  30.    echo.
  31.    call :colorEcho 0C "#"
  32.    call :colorEcho 07 "    If you're seeing this after clicking on a start menu icon,"
  33.    call :colorEcho 0C "   #"
  34.    echo.
  35.    call :colorEcho 0C "#"
  36.    call :colorEcho 07 "  then right click on the file and select 'Run As Administrator'"
  37.    call :colorEcho 0C " #"
  38.    echo.
  39.    call :colorEcho 0C "#                                                                 #"
  40.    echo.
  41.    call :colorEcho 0C "###################################################################"
  42.    echo.
  43.    echo.

  44.    PAUSE
  45.    EXIT /B 1
  46. )

  47.    echo -----------------------------------------------
  48.    call :colorEcho 0C "                    WARNING"
  49.    echo.
  50.    call :colorEcho 0C "  This script will completely and permanently"
  51.    echo.
  52.    call :colorEcho 0C "      remove OneDrive from your computer."
  53.    echo.
  54.    call :colorEcho 0C "        Make sure all OneDrive documents"   
  55.    echo.
  56.    call :colorEcho 0C "       that are stored locally are fully"
  57.    echo.
  58.    call :colorEcho 0C "          backed up before proceeding."   
  59.    echo.
  60.    echo -----------------------------------------------
  61.    echo.

  62.    SET /P M=  Press 'Y' to continue or any other key to exit.
  63.         if %M% ==Y goto PROCESSKILL
  64.         if %M% ==y goto PROCESSKILL

  65.    EXIT /B 1


  66. @rem The following is based on info from here written by 'LK':
  67. @rem https://techjourney.net/disable-or-uninstall-onedrive-completely-in-windows-10/


  68. @rem Terminate any OneDrive process
  69. :PROCESSKILL
  70.    echo.
  71.    echo Terminating OneDrive process.
  72.    
  73. taskkill /f /im OneDrive.exe


  74. @rem Detect if OS is 32 or 64 bit
  75. reg Query "HKLM\Hardware\Description\System\CentralProcessor\0" | find /i "x86" > NUL && set OS=32BIT || set OS=64BIT

  76. if %OS%==32BIT GOTO 32BIT
  77. if %OS%==64BIT GOTO 64BIT


  78. @rem Uninstall OneDrive app
  79. :32BIT
  80.    echo.
  81.    echo This is a 32-bit operating system.
  82.    echo Removing OneDrive setup files.
  83.    
  84. %SystemRoot%\System32\OneDriveSetup.exe /uninstall
  85. GOTO CLEAN

  86. :64BIT
  87.    echo.
  88.    echo This is a 64-bit operating system.
  89.    echo Removing OneDrive setup files.
  90.    
  91. %SystemRoot%\SysWOW64\OneDriveSetup.exe /uninstall
  92. GOTO CLEAN


  93. @rem Clean and remove OneDrive remnants
  94. :CLEAN
  95.    echo.
  96.    echo Removing remaining OneDrive folders.
  97.    
  98.    rd "%UserProfile%\OneDrive" /Q /S
  99.    rd "%LocalAppData%\Microsoft\OneDrive" /Q /S
  100.    rd "%ProgramData%\Microsoft OneDrive" /Q /S
  101.    rd "C:\OneDriveTemp" /Q /S
  102.    
  103.    echo.
  104.    call :colorEcho 0C "If you see 'access denied' errors here, reboot and run this batch file again."
  105.    echo.



  106. @rem Delete and remove OneDrive in file explorer folder tree registry key
  107.    echo.
  108.    echo Removing OneDrive registry keys.
  109.    
  110.    IF EXIST "HKEY_CLASSES_ROOT\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" REG Delete "HKEY_CLASSES_ROOT\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" /f
  111.    IF EXIST "HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" REG Delete "HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" /f
  112.    REG ADD "HKEY_CLASSES_ROOT\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" /v System.IsPinnedToNameSpaceTree /d "0" /t REG_DWORD /f
  113.    
  114.    echo.
  115.    echo OneDrive Uninstall and cleaning completed.
  116.    echo.

  117.    PAUSE
  118.    echo So long and thanks for all the fish...
  119.    PING -n 2 127.0.0.1>nul
  120.    EXIT /B 1

  121.    
  122. @rem Settings for text colour

  123. :colorEcho
  124. echo off
  125. <nul set /p ".=%DEL%" > "%~2"
  126. findstr /v /a:%1 /R "^$" "%~2" nul
  127. del "%~2" > nul 2>&1i
复制代码

作者: chishingchan    时间: 2020-2-12 12:34
不用思考的将 71行改为:
SET M=Y
作者: hilsonma    时间: 2020-2-12 12:44
也可以把71-75行注释掉(每行前头加上::或rem)如:
::   SET /P M=  Press 'Y' to continue or any other key to exit.
::        if %M% ==Y goto PROCESSKILL
::        if %M% ==y goto PROCESSKILL
::
::   EXIT /B 1
作者: 黑色de郁金香    时间: 2020-2-12 13:46
chishingchan 发表于 2020-2-12 12:34
不用思考的将 71行改为:
SET M=Y

谢谢大神!确实管用!
作者: 黑色de郁金香    时间: 2020-2-12 13:47
hilsonma 发表于 2020-2-12 12:44
也可以把71-75行注释掉(每行前头加上::或rem)如:
::   SET /P M=  Press 'Y' to continue or any other k ...

谢谢大神!刚恢复了一遍系统试了下,这个方法也管用!
作者: ximenzi7    时间: 2020-2-23 00:54
老外的这个没有获取管理权限的代码,差评!
@echo OFF

REM 先判断管理员权限,无则获取

if exist "%SystemRoot%\SysWOW64" path %path%;%windir%\SysNative;%SystemRoot%\SysWOW64;%~dp0
bcdedit >nul
if '%errorlevel%' NEQ '0' (goto UACPrompt) else (goto UACAdmin)
:UACPrompt
%1 start "" mshta vbscript:createobject("shell.application").shellexecute("""%~0""","::",,"runas",1)(window.close)&exit
exit /B
:UACAdmin

@REM 设置彩色文本的变量
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do     rem"') do (
  set "DEL=%%a"
)
   echo ------Windows 10 OneDrive 卸载工具 V1.2------
   echo.
   echo -----------------------------------------------
   call :colorEcho 0C "               警告!          "
   echo.
   call :colorEcho 0C "      这个脚本将完全和永久     "
   echo.
   call :colorEcho 0C "   从你的计算机中删除OneDrive。"
   echo.
   call :colorEcho 0C "  请确认您所有的OneDrive文件   "   
   echo.
   call :colorEcho 0C "        已经全部保存在本地     "
   echo.
   call :colorEcho 0C "  请确保在操作之前已经作好备份."   
   echo.
   echo -----------------------------------------------
   echo.


echo; "取消请在3秒内按c"
CHOICE /t 3 /C YC /D Y >nul 2>nul
if %errorlevel% equ 1 goto PROCESSKILL
if %errorlevel% equ 2 exit /b 1

@rem 以下是根据来自这里的信息写的 by:'LK'
@rem https://techjourney.net/disable-or-uninstall-onedrive-completely-in-windows-10/


@rem 终止OneDrive的所有进程
:PROCESSKILL
   echo.
   echo Terminating OneDrive process.
   
taskkill /f /im OneDrive.exe


@rem 检测操作系统是32位还是64位
reg Query "HKLM\Hardware\Description\System\CentralProcessor\0" | find /i "x86" > NUL && set OS=32BIT || set OS=64BIT

if %OS%==32BIT GOTO 32BIT
if %OS%==64BIT GOTO 64BIT


@rem 卸载OneDrive应用程序
:32BIT
   echo.
   echo 这是32位的操作系统
   echo 删除OneDrive安装文件。
   
%SystemRoot%\System32\OneDriveSetup.exe /uninstall
GOTO CLEAN

:64BIT
   echo.
   echo 这是64位的操作系统
   echo 删除OneDrive安装文件。
   
%SystemRoot%\SysWOW64\OneDriveSetup.exe /uninstall
GOTO CLEAN


@rem 清理删OneDrive的残留文件
:CLEAN
   echo.
   echo 正在处理残留的OneDrive文件夹。
   
   rd "%UserProfile%\OneDrive" /Q /S
   rd "%LocalAppData%\Microsoft\OneDrive" /Q /S
   rd "%ProgramData%\Microsoft OneDrive" /Q /S
   rd "C:\OneDriveTemp" /Q /S
   
   echo.
   call :colorEcho 0C "如果你看到"拒绝访问"错误,重启计算机并再次运行该批处理文件。"
   echo.



@rem 删除资源管理器中的OneDrive文件夹和注册表键值
   echo.
   echo 删除OneDrive注册表项。
   
   IF EXIST "HKEY_CLASSES_ROOT\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" REG Delete "HKEY_CLASSES_ROOT\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" /f
   IF EXIST "HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" REG Delete "HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" /f
   REG ADD "HKEY_CLASSES_ROOT\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" /v System.IsPinnedToNameSpaceTree /d "0" /t REG_DWORD /f
   
   echo.
   echo OneDrive卸载清理完成
   echo.

   PAUSE
   echo 再见,感谢您的使用!
   timeout /3 >nul
   EXIT /B 1

   
@rem 设置文本颜色

:colorEcho
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1i
作者: 黑色de郁金香    时间: 2020-2-23 02:36
ximenzi7 发表于 2020-2-23 00:54
老外的这个没有获取管理权限的代码,差评!
@echo OFF

无忧真是卧虎藏龙!这个功能太方便了,连右键以管理员身份这一步都省了!谢谢大神!




欢迎光临 无忧启动论坛 (http://bbs.c3.wuyou.net/) Powered by Discuz! X3.3