Rclone mount - progrmatic umount under windows

and as @ncw has mentioned above.
"As far as I remember the only way to unmount a drive on Windows with rclone is to kill the rclone process."

so if that is true, then hardkill is the only way.

the solution would be for winfsp to have an easy way to unmount but i have been looking at the website and i cannot find the way so far.

also, @kapitainsky is using QT framework for webbrowsers on windows.
seems that no matter what, a hardkill will be needed.

I have suggested this enhancement in rclone github repo #3575

1 Like

Hi,
I have been unmounting already several months using the SendSignal executable and killing the mount window. No sign of lateral damages by now.
On the other hand, have you had a look to my reference this one

It is providing a way to unmount WinFSP, perhaps a way to go?

They claim:
The proper way to unmount a file system that uses WinFsp-FUSE is by sending it a Ctrl-C. On Windows this is done by calling GenerateConsoleCtrlEvent

@kapitainsky
And, by the way, thanks for making RcloneBrowser alive again!
A lot of progress since your first release!
CT.

yes, i am aware of that info,
the problem is that it is not safe to close the mount via winfsp, as rclone might be using caching and other features and could lead to data corruption.

please the my post
https://forum.rclone.org/t/rclone-to-respect-a-soft-kill-termination/12110/26

and about sendsignal.exe i have never got it to work once.
perhaps i am using an old version.
please, can you post a link to where you got your version?

thanks,

You are right about caching...

SendSignal... I have no more info that what I wrote:

On sending Control-C, I found also several executables that do it. A search for SendSignal and SendControl brings some of them.

I found very interesting

https://web.archive.org/web/20170909040729/http://www.latenighthacking.com/projects/2003/sendSignal/

I will try with
32bits https://www.dropbox.com/s/r96jxglhkm4sjz2/SendSignalCtrlC.exe?dl=0
Clean as today by Virustotal https://www.virustotal.com/#/file/bdd0a7c3f14d1105a81cbb32d75762dd948da10bb227bf27c9c4ff09654ee8a3/detection
(this is for info for those interested; note that your safety is your call do not blame me…)

And
64bits https://www.dropbox.com/s/hhe0io7mcgcle1c/SendSignalCtrlC64.exe?dl=0
Clean also by Virrustotal today
https://www.virustotal.com/#/file/29711209fed703199c7cc75b402e10708cdaaec9169a0b297167588308b3b58e/detection

I will upload the bats I am using so you can try with them.

In the first link I remember seeing links to the source code of SendSignal, but I have not checked if they work.

CT

interesting, i had found a .exe named SendSignal.exe and that never worked for me.
i will try your links.

and yes, i already read that web.archive.org link but thanks for that anyway.

thanks,

Currently I just use Taskill

Bat to mount

SET mountLetter=H
SET myconfig=C:\ConfigFolder\rclone-conf-POINTER.txt
SET rcloneexe=C:\RCloneFolder\rclone.exe
chcp 65001>Nul

TITLE MOUNTED_%MountLetter%

%_rcloneexe% --user-agent yourAgent --config %_myconfigb% --vfs-cache-mode full mount REMOTENAME:FOLDERNAME %MountLetter%:

ECHO END
PAUSE
EXIT

Bat to UNMOUNT

SET MountLetter=H
SET WindowName=MOUNTED_%MountLetter%

for /f "tokens=2 USEBACKQ" %%f IN (tasklist /NH /FI "WINDOWTITLE eq %WindowName%*") Do TASKKILL /PID %%f

PAUSE

real nice code there,

sure, we all agree that taskkill will work with rclone.exe if there is a window to kill.
and i think @thestigma has shared some code similar to yours, using TITLE

but what if there is no window, then what?

SendSignal of course

the issue is that the developer of rclonebrowser, is having issues killing rclone.exe on windows.

in any event, sendsignal.exe and the SendSignalCtrlC64.exe as suggested by you do not work for me at all. i have tried many times, many different ways.
believe me, i want them to work, really i do.

i tend to run paranoid and i ran those sendsignal.exe, SendSignalCtrlC.exe and SendSignalCtrlC64.exe inside a virtual machine to be safe.

it is kinda of creepy to use some unknown and unsigned .exe and not know where it came from other then a dropbox and its unintended consequences.

what is the exact version of micro$oft windows on your system?

here is what always happens with those .exe

tasklist /fi "imagename eq rclone.1.49.4.exe"

Image Name PID Session Name Session# Mem Usage
========================= ======== ================ =========== ============
rclone.1.49.4.exe 13412 Console 1 24,392 K

SendSignalCtrlC.exe 13412
Sending ctrl-c signal to process 13412...
CreateRemoteThread failed with 0x00000005.
StartRemoteThread failed with 0x00000005.
0x00000005 == (FormatMessage failed)

I do not run anymore anything outside a virtual machine... with a good snapshot strategy. Only way to be more or less safe... until someone finds a way to filtrate from the guest to the host... but that is a different league...

Yes, using dark code is uneasy. No signal from malware to date from the exes pointed to. But I remember having seen a pointer to the source.

Anyhow, today there are fresher references if you are a coder; seems to be a very popular topic indeed...

Have you had a view to https://github.com/alirdn/windows-kill ?

https://stackoverflow.com/questions/813086/can-i-send-a-ctrl-c-sigint-to-an-application-on-windows looks providing also good pointings.

https://codetitans.pl/blog/post/sending-ctrl-c-signal-to-another-application-on-windows

I have it running somewhere in one VM, will try to locate it.

so you are like me, paranoid!

thanks, i will check out those links.

If you google for the error you find interesting answers; some point to using a 32bit signal to a 64bits process or reverse. Others to waiting for confirmation (Y/N) that you cannot see. Others to not having privileges enought to kill the process.

Interesting is
https://windows-hexerror.linestarve.com/q/so25142403-In-Windows-7-how-to-send-a-Ctrl-C-or-Ctrl-Break-to-a-separate-process

It shows

>SendSignal 26320
Sending signal to process 26320...
CreateRemoteThread failed with 0x00000005.
StartRemoteThread failed with 0x00000005.
0x00000005 == Access is denied.

finally.. the answer:

"windows-kill worked perfectly and managed to resolve access denial issues faced with SendSignal. A privileged user would have to run it as well of course."

Finally, this looks as the initial sendsignal code:

But windows-kill seems the most promising way for you.

CT

Just for the record.
Issue is now deprecated in relation to programatically killing the mount, as rclone developed such capability via rc - see https://github.com/rclone/rclone/issues/3575
On the other hand, thread provides ways to solve batch handling of mounts and unmounts.
CT

1 Like

For anyone interested in mounts using windows Batch Scripts, I can confirm that mounts can be mounted with rclone [even with hidden consoles using CMDOW (free) - https://ritchielawrence.github.io/cmdow/ ] and can be killed either with taskkill or using windows-kill - sends ctrl-C signal see https://github.com/alirdn/windows-kill

Note that depending on how the mount is launched, you will be able to kill the window that equates to sending a ctrl-C signal or will need to kill the process by PID.

Note that CMDOW allows to use window handlers instead of window titles, as well as to know the PID of the process that opened a window (even hidden), so any operation can be done even to hidden consoles...

In practice, my bats mount a remote and open an explorer in the mounted folder; mounting is behind the curtains using hidden consoles. Then, when I am not interested in that mount, I launch another bat that destroys the explorer window and unmounts cleanly the remote.

For me SendSignalCtrlC64.exe works as well as windows-kill; I recommend windows-kill that is open source. For SendSignalCtrlC64.exe see previous post.

Other utilities can be used to launch hidden consoles, such as hstart (shareware) but I have not found any benefits on top of cmdow.

Note that my set up involves administrative privileges. Some operations might not work without them, or might, but I have not tested them.

Enjoy
CT

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.