How to ensure network drives are connected for an application?

前端 未结 5 2152
小蘑菇
小蘑菇 2021-01-18 15:03

I have a desktop Windows application that is installed in small office environments.

The application uses an .MDB database file as its database which is

5条回答
  •  情书的邮戳
    2021-01-18 15:42

    You should use UNC paths, because not everyone will have your drive mapped to the same letter.

    Determine UNC path

    First, I would determine the UNC path of your file as it exists on your local computer at F:\data\db.mdb using one of the techniques found here:

    • Creating UNC paths from mapped drives

    Basically, you look at the way Windows Explorer lists the network mapped drive, then use this to deduce the UNC path.

    Check Availability using WMI

    Assuming the drive is actually mapped on every local computer that plans to use the application, use the Win32_MappedLogicalDisk class to determine availability of the mapped network drive.

    I have some sample code here that can be adapted to determine whether a given network drive is available (scroll down to the Mapped Drives Information section). You check .ProviderName to match the UNC path, so you know which is the correct drive, then check the value of .Availability to determine if the mapped network drive can be accessed.

提交回复
热议问题