Code asking OS if a dir is network shared?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

A few days ago I asked how to allow apps to run only on a stand-alone
machine, and not on a network or server, and got some great code for
determining OS version, etc.

However, one suggestion made was to "access the directory where the app is
running from and then ask the OS if the drive is a networked share.", but no
code example was given. I know how to find the app startup directory, but
how do I “ask the OS if the drive is a networked share."?? Does anybody have
coding for this? Since I will be checking this each time the app starts, I
hope to find a method that is fast, and does not require checking the startup
path, string by string, against a large collection.

Thanks to all who take time to help the rest of us!

Regards,
pcad1
 
Hi,

You may want to use GetDriveType() Win32 API. Below is an example:

public class MainClass
{
[DllImport("kernel32.dll")]
public static extern int GetDriveType (string lpRootPathName);

public static void Main()
{
if (GetDriveType (@"F:\") == 4) // Remote/network drive
{
Console.WriteLine ("F: is a network mapped drive");
}
}
}

Hope this helps.

A few days ago I asked how to allow apps to run only on a stand-alone
machine, and not on a network or server, and got some great code for
determining OS version, etc.

However, one suggestion made was to "access the directory where the app is
running from and then ask the OS if the drive is a networked share.", but no
code example was given. I know how to find the app startup directory, but
how do I "ask the OS if the drive is a networked share."?? Does anybody
have
coding for this? Since I will be checking this each time the app starts, I
hope to find a method that is fast, and does not require checking the
startup
path, string by string, against a large collection.

Thanks to all who take time to help the rest of us!

Regards,
pcad1
 
Back
Top