Click to See Complete Forum and Search --> : Run a C# .exe program from a shared network drive/directory


fanningm
November 6th, 2002, 03:13 PM
I'm having trouble finding information to help me understand what I need to include in a C# program (see below along with the resulting error message) in order to make it so that it can be run from a shared network location on each of my client workstations. I can run the program locally of course. I'm sure it has to do with security permissions in the .NET Framework, but I'm having very little success in understanding how this needs to work.

Do I include the following code (or a modification thereof)?
--------------------------------------------------------------------------
using System.Security;
using System.Security.Permissions;

[assembly:UIPermissionAttribute(SecurityAction.RequestMinimum, Unrestricted=true)]
[assembly:FileIOPermissionAttribute(SecurityAction.RequestMinimum, All="C:\\")]
--------------------------------------------------------------------------

Hep me, please!!!


Here is the code to this very basic console app:

Code:
=====
using System;
using System.IO;

namespace ConsoleApplication1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
FileInfo fileInfo = new FileInfo(@"C:\temp\test.txt");
string FileDir = fileInfo.DirectoryName;

Console.WriteLine(FileDir);
//
}
}
}



Error Msg is:
=========
Unhandled Exception: System.Security.Policy.PolicyException: Required permissions cannot be acquired

CPCericola
November 8th, 2002, 07:55 PM
What user is it running as? If you're running it as a user which does not have read/write access to the network drive that could do it. Is it running as a domain user?

fanningm
November 11th, 2002, 09:15 AM
Actually, it has to do with .NET security rather than Windows security. If you look at Start/Programs/Administrative Tools/Microsoft .NET Framework Configuration (or the .NET Framework Wizards) you'll probably see what I'm talking about. I've received many replies on this topic on a couple of other forums. I'll direct you to this one since it seems to have a majority of the information collected together. I'm still undecided as to which way I will go in handling this. For now, I've simply opened up the security ("local intranet") settings in the .NET Framework Wizards all the way on the client machine so that the source .exe on the server directory can be run. Here is the link to one of the other forums I mentioned:

http://www.csharphelp.com/board2/read.html?f=1&i=14849&t=14849