Venkatesh Velugubantla
asked on
help!! my .exe running on my box but not on someother box in LAN
Hi all..
I have a problem. I have the following peice of code:
using System;
using System.IO;
using System.Security.Permission s;
using System.Reflection;
namespace FileonLan
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
string path = @"\\PC1\New Folder\temp.txt";
try
{
if (!File.Exists(path))
{
// Create a file to write to.
using (StreamWriter sw = File.CreateText(path))
{
sw.WriteLine("Hello");
sw.WriteLine("And");
sw.WriteLine("Welcome");
}
}
// Open the file to read from.
using (StreamReader sr = File.OpenText(path))
{
string s = "";
while ((s = sr.ReadLine()) != null)
{
Console.WriteLine(s);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToStr ing());
Console.ReadLine();
}
}
}
}
this is running fine when I run it from my pc. but if I copy the executable to any computer in my LAN, its giving the following error
System.Security.SecurityEx ception: Request for the permission of type System.Sec
urity.Permissions.FileIOPe rmission, mscorlib, Version=1.0.5000.0, Culture=neutra
l, PublicKeyToken=b77a5c56193 4e089 failed.
at System.Security.CodeAccess SecurityEn gine.Check Helper(Per missionSet granted
Set, PermissionSet deniedSet, CodeAccessPermission demand, PermissionToken permT
oken)
at System.Security.CodeAccess SecurityEn gine.Check (Permissio nToken permToken,
CodeAccessPermission demand, StackCrawlMark& stackMark, Int32 checkFrames, Int32
unrestrictedOverride)
at System.Security.CodeAccess SecurityEn gine.Check (CodeAcces sPermissio n cap, S
tackCrawlMark& stackMark)
at System.Security.CodeAccess Permission .Demand()
at System.IO.FileStream..ctor (String path, FileMode mode, FileAccess access,
FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFr
omProxy)
at System.IO.FileStream..ctor (String path, FileMode mode, FileAccess access,
FileShare share, Int32 bufferSize)
at System.IO.StreamWriter.Cre ateFile(St ring path, Boolean append)
at System.IO.StreamWriter..ct or(String path, Boolean append, Encoding encodin
g, Int32 bufferSize)
at System.IO.StreamWriter..ct or(String path, Boolean append)
at System.IO.File.CreateText( String path)
at FileonLan.Class1.Main(Stri ng[] args)
i've serached on google and found that the following liks are the most useful links for me
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/RSPROG/htm/rsp_prog_rdl_2l7m.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/RSPROG/htm/rsp_prog_extend_install_8epc.asp
http://www.blog.coryisakson.com/PermaLink,guid,4c5a21b0-dfa7-4947-ac76-ee4b3e12e020.aspx
but even after going through those links, I am not able to rectify the problem.. can anyone help me??
I have a problem. I have the following peice of code:
using System;
using System.IO;
using System.Security.Permission
using System.Reflection;
namespace FileonLan
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
string path = @"\\PC1\New Folder\temp.txt";
try
{
if (!File.Exists(path))
{
// Create a file to write to.
using (StreamWriter sw = File.CreateText(path))
{
sw.WriteLine("Hello");
sw.WriteLine("And");
sw.WriteLine("Welcome");
}
}
// Open the file to read from.
using (StreamReader sr = File.OpenText(path))
{
string s = "";
while ((s = sr.ReadLine()) != null)
{
Console.WriteLine(s);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToStr
Console.ReadLine();
}
}
}
}
this is running fine when I run it from my pc. but if I copy the executable to any computer in my LAN, its giving the following error
System.Security.SecurityEx
urity.Permissions.FileIOPe
l, PublicKeyToken=b77a5c56193
at System.Security.CodeAccess
Set, PermissionSet deniedSet, CodeAccessPermission demand, PermissionToken permT
oken)
at System.Security.CodeAccess
CodeAccessPermission demand, StackCrawlMark& stackMark, Int32 checkFrames, Int32
unrestrictedOverride)
at System.Security.CodeAccess
tackCrawlMark& stackMark)
at System.Security.CodeAccess
at System.IO.FileStream..ctor
FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFr
omProxy)
at System.IO.FileStream..ctor
FileShare share, Int32 bufferSize)
at System.IO.StreamWriter.Cre
at System.IO.StreamWriter..ct
g, Int32 bufferSize)
at System.IO.StreamWriter..ct
at System.IO.File.CreateText(
at FileonLan.Class1.Main(Stri
i've serached on google and found that the following liks are the most useful links for me
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/RSPROG/htm/rsp_prog_rdl_2l7m.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/RSPROG/htm/rsp_prog_extend_install_8epc.asp
http://www.blog.coryisakson.com/PermaLink,guid,4c5a21b0-dfa7-4947-ac76-ee4b3e12e020.aspx
but even after going through those links, I am not able to rectify the problem.. can anyone help me??
Does the person logged in that machine has write access to \\PC1\New Folder\temp.txt?
ASKER
yeah... he has full controls
and the exe is on that PC's HDD or somewhere on the LAN?
ASKER
I just copied my exe from E:\C# Programs\FileonLan\FileonL an\bin\Deb ug to \\PC1\New Folder\ and tried running from there also but it dint work. i also tried it from \\PC2\Temp\ and even that dint work
I think you are running is from LAN. Just to confirm. Where is the exe and where are you running from?
ASKER
>> and the exe is on that PC's HDD or somewhere on the LAN?
ok here it is.. lemme make it more clear. i copied the exe to \\PC1\New Folder\.
now here is the problem. if i go an login to PC1 directly or using Remote Desktop and then run the exe, its creating the file but if I access the same exe from my box using \\PC1\New Folder\FileOnLan.exe, its giving me the exception
ok here it is.. lemme make it more clear. i copied the exe to \\PC1\New Folder\.
now here is the problem. if i go an login to PC1 directly or using Remote Desktop and then run the exe, its creating the file but if I access the same exe from my box using \\PC1\New Folder\FileOnLan.exe, its giving me the exception
ASKER
>> I think you are running is from LAN. Just to confirm. Where is the exe and where are you running from?
yeah.. I am running it from LAN
yeah.. I am running it from LAN
ASKER
but i want to run it over lan
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
it worked.. thanx :)
I see that this is your first question on EE so you might not have read http:help.jsp#hi73 It is important to grade properly as it is kind of history that you maintain here.
ASKER
I am sorry! but i dint know about the grading system earlier. I found 3 options Excellent good and one more option. I thought I would be getting a detailed explanation on what to do and how to do but I got some links instead of the explanation.. so I graded B. Moreover. those 2 links alone did not provide me the info required.. I went through a few more links..
neways.. thanx for ur quick response. may be I should have given A but I cant change my grade now. I will be careful while grading in future
neways.. thanx for ur quick response. may be I should have given A but I cant change my grade now. I will be careful while grading in future
>> I thought I would be getting a detailed explanation
Since the support pages have so detailed explanation, there is no point in repeating all the information again. However, if there is anything on the article that needs further explanation, you should have asked.
You can change the grade by poting a zero point question iin http:Community_Support with a link to this question. It is more important for you to understand the grading system so if you take care of that from now onwards, that is fine.
Since the support pages have so detailed explanation, there is no point in repeating all the information again. However, if there is anything on the article that needs further explanation, you should have asked.
You can change the grade by poting a zero point question iin http:Community_Support with a link to this question. It is more important for you to understand the grading system so if you take care of that from now onwards, that is fine.
ASKER
>>Since the support pages have so detailed explanation, there is no point in repeating all the information again. However, if there >>is anything on the article that needs further explanation, you should have asked.
Ur reply was quick and appropriate but the fact is that its not complete. U posted 2 links which inturn made me search some more links to get the entire solution.
>>You can change the grade by poting a zero point question iin http:Community_Support with a link to this question. It is more >>important for you to understand the grading system so if you take care of that from now onwards, that is fine.
I seriously dont think the answer should be awarded A and I agree its better than B. ok... because u are so keen about the grade, I will post a link in the support section. I already awarded u with points.. I am not worried about which grade u get.. I am worried just about my solution
thanx.
Ur reply was quick and appropriate but the fact is that its not complete. U posted 2 links which inturn made me search some more links to get the entire solution.
>>You can change the grade by poting a zero point question iin http:Community_Support with a link to this question. It is more >>important for you to understand the grading system so if you take care of that from now onwards, that is fine.
I seriously dont think the answer should be awarded A and I agree its better than B. ok... because u are so keen about the grade, I will post a link in the support section. I already awarded u with points.. I am not worried about which grade u get.. I am worried just about my solution
thanx.