Hello!This time I would like to introduce an example of creating a batch file that disables the OneDrive function.
OneDrive is a standard file synchronization software for Windows.This syncing movement can get in the way or cause updates to fail.
In such a case, let's disable OneDrive with a batch file quickly!
Thing you want to do
I want to stop the synchronization function without uninstalling OneDrive.
I want to disable the function when I execute a batch file.
@echo off cd /d %~dp0 rem ①管理者権限チェックし自動で管理者実行 whoami /priv | find "SeDebugPrivilege" > nul if %errorlevel% neq 0 ( @powershell start-process %~0 -verb runas exit ) rem ②OneDriveが起動していたら終了する tasklist |findstr "OneDrive" if %errorlevel% equ 0 ( taskkill /f /im OneDrive.exe ) rem ③レジストリでOneDriveの同期機能を無効化する reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\OneDrive" /v "DisableFileSyncNGSC" /t REG_DWORD /d 1 /f pause
(XNUMX) Administrator authority check and administrator execution automatically
Administrator privileges are required because it requires writing to the registry.
As usual, I put a script that automatically promotes to the administrator.
If you want to know more, please click below.
② Exit if OneDrive is running
tasklist | findstr "OneDrive" if% errorlevel% equ 0 (taskkill /f /imOneDrive.exe)
"Tasklist" is a command that returns all the tasks that are currently running.I'm looking for the word "OneDrive" in "findstr".
If OneDrive is found, it is terminated by the "taskkill" command that terminates the specified task.
The option "/ f" is an option to forcibly terminate, and "/ im" is an option to specify the process to terminate with the image name.
③ Disable the OneDrive sync function in the registry
You can disable OneDrive sync period with the following registry key.
Registry key: HKEY_LOCAL_MACHINE \ SOFTWARE \ Policies \ Microsoft \ Windows \ OneDrive Subkey: DisableFileSyncNGSC Key type: REG_DWORD value When 1: Invalid When 0: Valid
I want to disable it this time, so if you set this value to 1, it's OK.
If you don't set up this registry, you'll have to quit OneDrive every time you boot.
This time, the main thing is to disable synchronization, so if you set this registry, it will not synchronize even if OneDrive is running.
This time, I introduced an example of creating a batch file that disables the OneDrive function.
Of course, if you uninstall it, you do not have to do this kind of processing, but I created it as an example that it is possible to leave it in for the time being.
OneDrive is a very useful tool for backing up and sharing to your own PC.
You can copy it from the WEB, and if you have a Microsoft account, it will synchronize as soon as you log in.
There is no problem if synchronization is completed, but if the environment continues to be in sync, a failure may occur based on that.
If you don't use it, you can uninstall it, but if you think something is wrong, you can stop the function even temporarily.
I hope it helps you.