Link to home
Start Free TrialLog in
Avatar of Venkatesh Velugubantla
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.Permissions;
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.ToString());
                        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.SecurityException: Request for the permission of type System.Sec
urity.Permissions.FileIOPermission, mscorlib, Version=1.0.5000.0, Culture=neutra
l, PublicKeyToken=b77a5c561934e089 failed.
   at System.Security.CodeAccessSecurityEngine.CheckHelper(PermissionSet granted
Set, PermissionSet deniedSet, CodeAccessPermission demand, PermissionToken permT
oken)
   at System.Security.CodeAccessSecurityEngine.Check(PermissionToken permToken,
CodeAccessPermission demand, StackCrawlMark& stackMark, Int32 checkFrames, Int32
 unrestrictedOverride)
   at System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, S
tackCrawlMark& stackMark)
   at System.Security.CodeAccessPermission.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.CreateFile(String path, Boolean append)
   at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encodin
g, Int32 bufferSize)
   at System.IO.StreamWriter..ctor(String path, Boolean append)
   at System.IO.File.CreateText(String path)
   at FileonLan.Class1.Main(String[] 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??
Avatar of amit_g
amit_g
Flag of United States of America image

Does the person logged in that machine has write access to \\PC1\New Folder\temp.txt?
Avatar of Venkatesh Velugubantla
Venkatesh Velugubantla

ASKER

yeah... he has full controls
and the exe is on that PC's HDD or somewhere on the LAN?
I just copied my exe from E:\C# Programs\FileonLan\FileonLan\bin\Debug 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?
>> 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
>> 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
but i want to run it over lan
ASKER CERTIFIED SOLUTION
Avatar of amit_g
amit_g
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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
>> 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.

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.