473,387 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

IO-statements do not execute on network-drive ???

Hi,

executing the following on a local drive works fine :

FileStream wLog;
wLog=File.OpenRead(@"d:\Log.txt");

but executing the same code on a network drive creates a FileIOPermission-exception.
although the user has full control on the drive where the application is running.
Actually, any IO-statement creates an exception ???

Is it some kind of .NET permission that must be set or something else ?

any help greatly appreciated !!

thanks
Chris

************************************************** ********************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
Nov 17 '05 #1
4 3565
> executing the following on a local drive works fine :

FileStream wLog;
wLog=File.OpenRead(@"d:\Log.txt");

but executing the same code on a network drive creates a FileIOPermission-exception. although the user has full control on the drive where the application is running. Actually, any IO-statement creates an exception ???

Is it some kind of .NET permission that must be set or something else ?

Yes, the .NET have built in security by default that disabled
LAN/Internet/... access by default decreasing the risk that if a program is
taken over by a worm/trojan/virus/bug that it accidently access the
Internet.

Two things must happen in order to access the LAN network drive.
1. You as programmer must tell the program compiler in the assembly for
example that this program is allowed to access the LAN drives. If you just
create a silly clock that does not need LAN or Internet access, then this
program should not access the LAN or Internet.

2. The person that installs this program on his computer must give rights
for that program to access the LAN/Internet/... It is not because that the
programmer wants LAN access that a administrator likes a unknown program so
browser through the LAN folders. It might be a Trojan.

You will also note that the program, by default refuses to execute when
double clicked on a shared drive. It must be copied to a local, folder.
Unless it is fully trusted and designed by the programmer to run from a
network drive.

Configuring the rights are done through Control panel, administrative
tools/... but is very complicated for simple users in my opinion. So an
alternative way is creating a setup, that installs the program and also
configures the correct rights. This setup can be launched form network
folder since it is a conventional executable, and has by default enough
rights. It also have rights to run parts of the .NET code that configures
the this program with enough rights automatically. A .NET program has no
rights to configure it's own rights, but when it is done by the setup it
can.

I think that you have a lot of reading to do before you understand it all.
;-)
Nov 17 '05 #2
Hi Olaf,

thanks for your comments but when you say

"... You as programmer must tell the program compiler in the assembly for example that this program is allowed to access the LAN drives... "

how is this done then ?

thanks.
Chris

************************************************** ********************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
Nov 17 '05 #3
> thanks for your comments but when you say

"... You as programmer must tell the program compiler in the assembly for example that this program is allowed to access the LAN drives... "
how is this done then ?

Multiple possible ways, statically in the AssemblyInfo.cs, but alos dynamic
only for those functions that you need to access LAN, and the rest should
default not access LAN.

This is one way when you put this in the AssemblyInfo.cs (emulating a
conventional exe):

[assembly:SecurityPermission(SecurityAction.Request Minimum, Execution =
true)]
[assembly:SecurityPermission(SecurityAction.Request Minimum,
UnmanagedCode=true)]
[assembly:FileIOPermission(SecurityAction.RequestMi nimum,
Unrestricted=true)]
[assembly:RegistryPermission(SecurityAction.Request Minimum, All="*")]
[assembly:ZoneIdentityPermission(SecurityAction.Req uestMinimum,Zone=Security
Zone.NoZone)]

Note I have provided most functions, you should activate only those that you
really need.

This is the one that you might want to activate:
[assembly:FileIOPermission(SecurityAction.RequestMi nimum,
Unrestricted=true)]

You should at least try to read about that .NET security model, complicated
stuff, but you have to understand it.

Nov 17 '05 #4
> This is the one that you might want to activate:
[assembly:FileIOPermission(SecurityAction.RequestMi nimum,
Unrestricted=true)]

I believe that this link explains how to create a installer that
automatically configures for the neccesary rights so that the program gets
full LAN and Internet access, without need of the user to be a administrator
expert.

http://msdn.microsoft.com/library/de...ms11122002.asp

Basically is this, you create a class from
System.Configuration.Install.Installer that has [RunInstaller(true)] as
attribute telling that the installer can be executed remotely (by the
setup). Then in your steup project you tell it to execute that one method
defined in that class. Since the Setup is not a .NET program and the user
must decide for themselves that this setup is a reliable program (since you
downloaded it form a reliable source), the setup gets enough permission to
actually execute and configure the administrative rights.

.......
PermissionSet permSet1 = new NamedPermissionSet("FullTrust");
StrongNamePublicKeyBlob key = new StrongNamePublicKeyBlob(publicKey);
IMembershipCondition membership1 = new StrongNameMembershipCondition(key,
null, null);

// Create the code group
PolicyStatement policy1 = new PolicyStatement(permSet1);
CodeGroup codeGroup1 = new UnionCodeGroup(membership1, policy1);
codeGroup1.Description = "Full trust permissions for my product!";
codeGroup1.Name = "Skyscan full trust";

..... see the link but you get the idea..

machinePolicyLevel.RootCodeGroup.AddChild(codeGrou p1);
SecurityManager.SavePolicy();
.......
Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Daniel Ehrenberg | last post by:
Io (www.iolanguage.com) is a new programming language that's purely object-oriented (but with prototypes), has a powerful concurrency mechanism via actors, and uses an extremely flexible syntax...
6
by: Don | last post by:
I'm having problems working with a streamwriter object. After closing the streamwriter and setting it to Nothing, I try to delete the file it was writing to, but I always get the following error...
7
by: Nathan Sokalski | last post by:
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving,...
4
by: pank7 | last post by:
hi everyone, I have a program here to test the file IO(actually output) with buffer turned on and off. What I want to see is that there will be obvious differece in time. Here I have an input...
1
by: kkizer | last post by:
I have a problem with this simple code below. Moving the files works perfectly, but once in a blue moon the file that it is trying to move dissapears before it can move it. and when this happens...
2
by: jjlagtap | last post by:
Hey everyone When I try to open a file i get the Exception listed below. The weird thing is it works when I run the web app locally and when i use a remote server and open a file on my computer....
2
by: rajeshgubba | last post by:
Hi all, Can anybody help me how to resolve the below problem? I am trying to read xml file from an URL link as shown below, HttpConnection conn = (HttpConnection)Connector.open(Url);...
9
by: Keith G Hicks | last post by:
I'm having a lot of trouble with "file in use" errors in my "folder watcher" project. Starting and stopping the watcher and reading my XML file work fine. Once the watcher is started, I'm reading...
2
by: somsub | last post by:
Hi all, Here is my samle code use strict ; use warnings ; use IO::Uncompress::Unzip ; When I compiled this three lines of code in win32 I got error like below.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.