简体   繁体   English

暂停/恢复OneDrive与C#同步

[英]Pausing/Resuming OneDrive syncing with C#

I am looking for a way to set a schedule for OneDrive in a program I am developing. 我正在寻找一种在正在开发的程序中为OneDrive设置时间表的方法。 This schedule will only allow OneDrive to sync from midnight (00:00) to 6AM (06:00). 此计划仅允许OneDrive从午夜(00:00)到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. 我知道该程序的调度部分,我正在苦苦挣扎的部分是找到一种方法,该方法可以在凌晨6点暂停同步并在午夜恢复。

If someone could help me find a way to programmatically Pause and Resume OneDrive sync I would be grateful. 如果有人可以帮助我找到以编程方式暂停和恢复OneDrive同步的方法,我将不胜感激。

So there are mainly 2 methods that I would go so far to archive this, let me explain you: 因此,到目前为止,我主要有2种方法来存档此文件,下面让我解释一下:

Sleep the proccess Form CMD 睡眠过程表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) 您将必须首先找到进程ID(OneDrive使用的程序应该是SkyDrive.exe ,并且在System32下)
You will also have to install Invoke-WindowsApi before running that command. 您还必须在运行该命令之前安装Invoke-WindowsApi

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

在此处输入图片说明

You can create a batch for this. 您可以为此创建一个批处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM