473,606 Members | 2,115 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Hi,

executing the following on a local drive works fine :

FileStream wLog;
wLog=File.OpenR ead(@"d:\Log.tx t");

but executing the same code on a network drive creates a FileIOPermissio n-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 3582
> executing the following on a local drive works fine :

FileStream wLog;
wLog=File.OpenR ead(@"d:\Log.tx t");

but executing the same code on a network drive creates a FileIOPermissio n-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:Securi tyPermission(Se curityAction.Re questMinimum, Execution =
true)]
[assembly:Securi tyPermission(Se curityAction.Re questMinimum,
UnmanagedCode=t rue)]
[assembly:FileIO Permission(Secu rityAction.Requ estMinimum,
Unrestricted=tr ue)]
[assembly:Regist ryPermission(Se curityAction.Re questMinimum, All="*")]
[assembly:ZoneId entityPermissio n(SecurityActio n.RequestMinimu m,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:FileIO Permission(Secu rityAction.Requ estMinimum,
Unrestricted=tr ue)]

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:FileIO Permission(Secu rityAction.Requ estMinimum,
Unrestricted=tr ue)]

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.Configur ation.Install.I nstaller that has [RunInstaller(tr ue)] 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 NamedPermission Set("FullTrust" );
StrongNamePubli cKeyBlob key = new StrongNamePubli cKeyBlob(public Key);
IMembershipCond ition membership1 = new StrongNameMembe rshipCondition( key,
null, null);

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

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

machinePolicyLe vel.RootCodeGro up.AddChild(cod eGroup1);
SecurityManager .SavePolicy();
.......
Nov 17 '05 #5

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

Similar topics

20
2443
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 because all code is a modifiable message tree. Like Python, it is dynamically typed, has a very clean syntax, produces short code, and is excruciatingly slow (on the same level as eachother). Io has a unique syntax combining Lisp's idea of...
6
10207
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 message: "The process cannot access the file "whatever" because it is being used by another process." I've even tried opening another file using the same streamwriter object before deleting the original file, but it's no use. Something keeps...
7
2298
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, the other in which I close the FileStream afterwards, although both return the same error. Here are the two versions of the code and the errors they each return (NOTE: I rebooted immediately before running each of these versions so that I knew they...
4
4171
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 file scales 1.1M, what I did is just copy it to another output file(ten times). But I don't think I see any difference. My file system is ext3, with debian sarge(kernel-2.6.8). Here is the main part of my program:
1
7138
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 the "System.IO.Move" goes in to a loop and keeps creating the file on the destination folder with a 0byte size and keeps entering the error in the log i have until someone stop the service. so what i cant figure out is since it catches the...
2
7939
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. When someone else uses the web app and tries to open a file using the remote server the error below happens. any help? **Code** C# - filepath is a valid file name which is passed via the form. System.IO.BinaryReader br = new...
2
8546
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); InputStream InputStream = conn.openInputStream();
9
2908
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 the text files from the watched folder line by line into variables and then posting them to a SQL table. All of the code for the form is shown below. And it works fine except for 2 issues. First issue: In the Finally of the Try for teh SQL...
2
6376
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
8009
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8432
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8078
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
5962
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5456
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3919
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3964
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2442
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1285
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.