Configuring Rclone mount as a Windows service

Quick disclosure: I have created the service in Windows 11 (home flavor)

Instructions

First you need to have your remote configured. Mount the remote and make sure that you have a working configuration.

You should have something similar to this command by now:

rclone mount "name of remote" mount_location --additional_swithces

i.e. actual command: rclone mount “bobbys-drive main” T: –vfs-cache-mode writes

( I have found the --vfs-cache-mode writes switch to be needed by my onedrive/sharepoint things)

You will also need the following information:

  • The path to your rclone binary - i.e. - C:\Program Files\rclone-o-mine\rclone.exe
  • The path to your rclone configuration -i.e. C:\Data\rclone-config\rclone.conf – your config file can be queried from rclone by running rclone config file
  • The name of your remote (already clear from your command – i.e. - “bobbys-drive main” )
  • Where are you mounting your remote (already clear from your command – i.e. - T: )
  • The name of the service (let’s say: “Bobbys-rclone”)
  • The Pretty name to display in the Services comandlet ((let’s say: “Bobbys Remote Drive”)

When you have all this info we build the command for the service

"C:\Program Files\rclone-o-mine\rclone.exe" --config=C:\Data\rclone-config\rclone.conf  mount "bobbys-drive main" T: --vfs-cache-mode writes

Test the command and make sure it works.

Next we format the command in order to add it to the service.

If your full command does not have any spaces as part of it’s parameters (this is not the example I have shown you so far). You will only have to add quotes around the whole thing… but this does not happen often.

If your full command has part of it that need quotes, then… first you add \ before all the quotes you already have:

 \"C:\Program Files\rclone-o-mine\rclone.exe\" --config=C:\Data\rclone-config\rclone.conf  mount \"bobbys-drive main\" T: --vfs-cache-mode writes

And then you add additional quotes at the start and end of the command:

"\"C:\Program Files\rclone-o-mine\rclone.exe\" --config=C:\Data\rclone-config\rclone.conf  mount \"bobbys-drive main\" T: --vfs-cache-mode writes"

Next we are going to build the sc create command that creates the service. Let’s put the parts together following this order:

sc create service_name binpath= "command" displayname= "pretty name" start= delayed-auto

(The start= delayed-auto gives our service a little less priority so it will start once most everything else is running)

So we take our info and we build the following:

sc create Bobbys-rclone binpath= "\"C:\Program Files\rclone-o-mine\rclone.exe\" --config=C:\Data\rclone-config\rclone.conf  mount \"bobbys-drive main\" T: --vfs-cache-mode writes" displayname= "Bobbys Remote Drive" start= delayed-auto

In order to run this we admin privileges, start a command prompt as an administrator.

Once we have the command prompt we run our command.

and we should get:

[SC] CreateService SUCCESS

We can do a net start of our service to check it. Also net stop to check it does stop.

If it does not work at first, we can delete the service with sc delete service_name and review

[Extra considerations]

This service should load and work fine when your PC starts, but you’ll only be able to start and stop it as an admin.

In order to give permission over it to non admin users you have to jump through additional hoops.

The best option I found is to use Microsoft’s Process Explorer – and in this link tells you how to do it: How to Allow Non-Admin User to Start/Stop Service in Windows | Windows OS Hub

1 Like