Results 1 to 6 of 6

Thread: SHChangeNotify for adding and removing disks

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2021
    Posts
    4

    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?

  2. #2
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,714

    Re: SHChangeNotify for adding and removing disks

    Send flush afterwards would be my guess.

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2021
    Posts
    4

    Re: SHChangeNotify for adding and removing disks

    Quote Originally Posted by fafalone View Post
    Send flush afterwards would be my guess.
    Thanks for the suggestion, but to no avail

  4. #4
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,444

    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

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2021
    Posts
    4

    Re: SHChangeNotify for adding and removing disks

    Quote Originally Posted by Zvoni View Post
    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)

  6. #6

    Thread Starter
    New Member
    Join Date
    Apr 2021
    Posts
    4

    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
  •  



Click Here to Expand Forum to Full Width