manif3st
manif3st

Reputation: 13

Pausing/Resuming OneDrive syncing with C#

I am looking for a way to set a schedule for OneDrive in a program I am developing. This schedule will only allow OneDrive to sync from midnight (00:00) to 6AM (06:00). The scheduling part of the program I know how to do, the part I am struggling with is finding a way to Pause the Sync at 6 AM and Resume it at midnight.

If someone could help me find a way to programmatically Pause and Resume OneDrive sync I would be grateful.

Upvotes: 1

Views: 1906

Answers (1)

Sid
Sid

Reputation: 14896

So there are mainly 2 methods that I would go so far to archive this, let me explain you:

Sleep the proccess Form CMD

Here it is the command:

Invoke-WindowsApi "kernel32" ([bool]) "DebugActiveProcess" @([int]) @(process_id_here)

You will have to find the process id First (the program used by OneDrive should be SkyDrive.exe and it is under System32)
You will also have to install Invoke-WindowsApi before running that command.

Shutdown the process and then restart it

You can shut down the process and then restart it at midnight, like this:

SkyDrive.exe /shutdown
SkyDrive.exe

enter image description here

You can create a batch for this.

Upvotes: 1

Related Questions