Run rclone as service on Windows — C# — DIY

John Gakhokidze
2 min readSep 1, 2020

--

Rclone is the great tool to work with the cloud storage from various providers. While it works as service on Linux, you need to use interactive shell to make it work on Windows systems. There are different solutions which involve 3rd party tools to make it work as service but they do not provide the same flexibility as service can provide.

VirtIOGroove open sourced quick solution in C# how to make it work as service on Windows on github
It is quick workable draft, with plenty of space to improve — any suggestions are welcome!

Let us take a look what we need:

  1. Visual Studio (Community Edition works fine)
  2. .Net Framework 4.8
  3. WinFSP
  4. rclone
  5. Some patience to read this post to the end :)

Binary Installation, Configuration, Service Compilation and Creation

  • Install software from steps 1 to 3 in previous section
  • Extract rclone and add path to folder where rclone was extracted to system %PATH%
  • run rclone config and configure cloud connection. Please see rclone documentation for details.
  • Clone github repository
  • Navigate to cloned github folder and import Solution to Visual Studio
  • Example in Service1.cs covers mounting Azure blob storage using SAS — example assumes , that you already configured rclone to use Azure. You can configure rclone with different cloud provider and replace cParams value

protected override void OnStart(string[] args)
{
WriteToFile("Service started " + DateTime.Now);
timer.Elapsed += new ElapsedEventHandler(OnElapsedTime);
timer.Interval = 20000;
timer.Enabled = true;
var cParams = "mount blob:poc c:\\Azure";
string filename = "rclone.exe";
try
{
var proc = System.Diagnostics.Process.Start(filename, cParams);
}
catch {
WriteToFile("Can not start services");
}

  • Once you are ok with parameters rebuild project.
  • You can now use c:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe- or whatever version you have from 4.x

c:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe drive:\<Path>\<to>\bin\Debug\RcloneWrapper.exe

Run services.msc and change Logon Account to user, under which you ran rclone config

Originally published at https://dev.to on September 1, 2020.

--

--