1

I have packaged a .NET application in the form of a .zip file. The user needs to unzip the file on his local hard drive to create a directory with an executable and associated resources. However, users keep unzipping the file on a network drive and execute the app from there, and they get problems because of this.

Can I force users to run the file from their local hard drive by displaying a message if they run it from a network drive and closing the app ?

Pierre Gardin
  • 684
  • 1
  • 8
  • 23
  • This might be what you're looking for: http://stackoverflow.com/questions/837488/how-can-i-get-the-applications-path-in-net-in-a-console-app. Once you know the path you could determine whether it is a network location. – Arj Aug 09 '12 at 09:23

1 Answers1

3

You only need to check if the path is a network path and give an error message.

Steps:

  1. Get path or running application:

    var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

  2. Check if path is a network path:

    [DllImport("shlwapi.dll")]

    private static extern bool PathIsNetworkPath(string pszPath);

    if(PathIsNetworkPath(path))...

  3. Give error message

Refer: PathIsNetworkPath

nunespascal
  • 17,584
  • 2
  • 43
  • 46