-
Apr 28th, 2021, 04:08 AM
#1
Thread Starter
New Member
SHChangeNotify for adding and removing disks
Hi VB-nerds,
I hope you can help: I have an application connecting to an ftp-site and adding that connection as local disk. I use rclone for that. As the disk not shows up automatically in Windows Explorer I use SHChangeNotify to do the job for me:
Private Declare Function SHChangeNotify Lib "Shell32.dll" (ByVal wEventID As Long, ByVal uFlags As Long, ByVal dwItem1 As Long, ByVal dwItem2 As Long) As Long
Private Const SHCNF_FLUSH As Long = &H1000
Private Const SHCNE_DRIVEADD As Long = &H100
Private Const SHCNE_DRIVEREMOVED As Long = &H80
Private Const SHCNF_PATH As Long = 5
This code to add the drive to Explorer works perfectly:
Call SHChangeNotify(0, SHCNF_FLUSH, 0, 0)
Call SHChangeNotify(SHCNE_DRIVEADD, SHCNF_PATH, strptr("K:"), 0)
But this one doesn't (I need this when I unmount the disk):
Call SHChangeNotify(0, SHCNF_FLUSH, 0, 0)
Call SHChangeNotify(SHCNE_DRIVEREMOVED, SHCNF_PATH, strptr("K:"), 0)
Any idea what I am doing wrong?
-
Apr 28th, 2021, 01:19 PM
#2
Re: SHChangeNotify for adding and removing disks
Send flush afterwards would be my guess.
-
Apr 29th, 2021, 06:31 AM
#3
Thread Starter
New Member
Re: SHChangeNotify for adding and removing disks
Originally Posted by fafalone
Send flush afterwards would be my guess.
Thanks for the suggestion, but to no avail
-
Apr 29th, 2021, 08:39 AM
#4
Re: SHChangeNotify for adding and removing disks
I've seen a lot of posts about "mounted" network-shares/external sites (ftp) which still show in Explorer but which are definitely disconnected.
By any chance: Is your K-Drive showing a red X in Explorer? (As in "disconnected")
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Apr 29th, 2021, 11:14 AM
#5
Thread Starter
New Member
Re: SHChangeNotify for adding and removing disks
Originally Posted by Zvoni
I've seen a lot of posts about "mounted" network-shares/external sites (ftp) which still show in Explorer but which are definitely disconnected.
By any chance: Is your K-Drive showing a red X in Explorer? (As in "disconnected")
No there is no red X in explorer. When you click the unmounted, but still visible disk you get a warning with "Drive K: is not available. Make sure the device is connected, blablabla..." What I just found out that if you open "This PC" in Explorer and unmount the disk and do the API calls the disk disappears from "This PC" (in the right window of Explorer), but in the left window it is still there.
BTW there is a typo in my first post (I left backslash out), so if you suggest that might be the problem, no... This is the code (that doesn't do the job)
Call SHChangeNotify(0, SHCNF_FLUSH, 0, 0)
Call SHChangeNotify(SHCNE_DRIVEREMOVED, SHCNF_PATH, strptr("K:"), 0)
-
Apr 30th, 2021, 10:18 AM
#6
Thread Starter
New Member
Re: SHChangeNotify for adding and removing disks
I found the solution: first remove the disks from Explorer and then unmount them, so:
'API calls to update Explorer
Call SHChangeNotify(SHCNE_DRIVEREMOVED, SHCNF_PATH, StrPtr( "K:"), 0)
Call SHChangeNotify(0, SHCNF_FLUSH, 0, 0)
Call SHChangeNotify(SHCNE_DRIVEREMOVED, SHCNF_PATH, StrPtr("L:"), 0)
Call SHChangeNotify(0, SHCNF_FLUSH, 0, 0)
'unmount/rclone
Shell """" & Environ("PROGRAMFILES") & "\Easy Booking\rclone.exe"" rc core/quit --rc-addr localhost:33333"
Shell """" & Environ("PROGRAMFILES") & "\Easy Booking\rclone.exe"" rc core/quit --rc-addr localhost:33334"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|