Run rclone as service on Windows — C# — DIY

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.

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Careers in Cloud

Features and Benefits of Bootstrap 4

Overfitting Software Design

How to Learn to Program: Writing Code

[Unity ECS] The Chunk data structure

Improve the quality of your OCR information extraction

[LeetCode]#20. Valid Parentheses

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
John Gakhokidze

John Gakhokidze

More from Medium

5G Network in a Box for Testing & Simulation Use Cases | Test & Validate 5G-Ready solutions On the…

Elastic Agent on Minikube

Open Weather APIs.

Dig Dug | TryHackMe