2

I'm new to c#, so please forgive me if i ask some entry level questions.

currently, I have a little windows form that have cancel button on it. I noticed that when i run it on local machine the cancel button works fine. but it gives me security exceptions when running from network location on xp machine. the exception is telling me I cannot call unmanaged code etc .... but my form only has one button and the code within eventhandler is: Application.Exit();

after googling around I found that I can make changes through mscorcfg.msc to give permission to intranet. this worked for me.

the other workaround I found is http://msdn.microsoft.com/en-us/library/aa288469(v=vs.71).aspx

however, this is a workaround for one machine only, what if I have a hundred machines????

so I assume there must be some other ways to deal with this problem, can anyone please help??

ikel
  • 1,790
  • 6
  • 31
  • 61

2 Answers2

3

It is a feature of the .NET framework itself : Code Access Security.

By default, code on a network share will run with the security level of LocalIntranet that have a lower level of privilege than if it is run on the local drive that is a "secure" location.

You can use the tool caspool to get rid of this limitation and give trust execution to an executable also on a network location, so for example :

caspol -machine -addfulltrust program.exe
aleroot
  • 71,077
  • 30
  • 176
  • 213
  • yes, i did find this tool caspol, but this is just for one machine, how about a hundred machines?? isn't there a way to do this within code?? – ikel Nov 05 '11 at 23:41
3

Update to a newer version of the framework. .Net no longer enforces this for network shares if you're running .Net 3.5 sp1 or later.

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794