473,406 Members | 2,377 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,406 software developers and data experts.

Giving a program permisions

Ok, the title might not be 100% clear, but i'll be more precise here

When i attempt to read an XML into an Dataset, i use the following line of code

Dataset1.ReadXml("C:\test.xml");

This works fine on my portable, but if i use it on a second PC, i get the following error.

Security Exception Was Unhandled
Request for the permission of type System.Security.Permissions.FileIOPermission, ... (this contains the public key, wich isn't too important for you guys i think)

if you didn't know, the language is C#, .NET framework 2.0.

I suspect it might be the permissions, i have the administrator name and pasword, is it possible to give my program those as well?

or is there another problem thats causing this?

any help so i can come to a solution would be apriciated :)
Oct 27 '06 #1
2 1734
I tried using Impersonating a diffrent perrson, giving the login and pasword of the admin, but i get an error, stating i don't have permision (to change my permisions)


Expand|Select|Wrap|Line Numbers
  1. //impersonate admin rights
  2.             Impersonator i = new Impersonator("Administrator", "Domain", "Pasword");
  3.             i.Impersonate();
  4.             //this the the location of the crystal report, if the report changes location, this needs to be updated
  5.             MyReport.Load("\\\\srv3\\home$\\programmas\\IntoToCr\\IntoToCr\\Arrival.rpt");
  6.             //Stop using admin rights
  7.             i.Undo();

The problem lies at this.impersonationContext = this.Logon().Impersonate();
wich i have made bold in the code of Impersonator.cs

I hope someone has a clue to a solution.

Impersonator.cs

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using System.Security.Principal;
  4. using System.Security;
  5. using System.Security.Permissions;
  6. namespace test
  7. {
  8.     /// <summary>
  9.     ///        Impersonator class allows client code to impersonate another domain user account 
  10.     ///        by handling underlying account authentication and security context manipulation
  11.     /// </summary>
  12.     public class Impersonator
  13.     {
  14.         // private members for holding domain user account credentials
  15.         private string username = String.Empty;
  16.         private string password = String.Empty;
  17.         private string domain = String.Empty;
  18.         // this will hold the security context for reverting back to the client after impersonation operations are complete
  19.         private WindowsImpersonationContext impersonationContext = null;
  20.  
  21.         // disable instantiation via default constructor
  22.         private Impersonator()
  23.         { }
  24.  
  25.         /// <summary>
  26.         /// The constructor, sets the username, domain and pasword
  27.         /// </summary>
  28.         /// <param name="username">Username with enough rigths</param>
  29.         /// <param name="domain"></param>
  30.         /// <param name="password">Password of the user</param>
  31.         public Impersonator(string username, string domain, string password)
  32.         {
  33.             // set the properties used for domain user account
  34.             this.username = username;
  35.             this.domain = domain;
  36.             this.password = password;
  37.         }
  38.  
  39.         private WindowsIdentity Logon()
  40.         {
  41.             IntPtr handle = new IntPtr(0);
  42.             handle = IntPtr.Zero;
  43.  
  44.             const int LOGON32_LOGON_NETWORK = 3;
  45.             const int LOGON32_PROVIDER_DEFAULT = 0;
  46.  
  47.             // attempt to authenticate domain user account
  48.             bool logonSucceeded = LogonUser(this.username, this.domain, this.password, LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, ref handle);
  49.  
  50.             if (!logonSucceeded)
  51.             {
  52.                 // if the logon failed, get the error code and throw an exception
  53.                 int errorCode = Marshal.GetLastWin32Error();
  54.                 throw new Exception("User logon failed. Error Number: " + errorCode);
  55.             }
  56.  
  57.             // if logon succeeds, create a WindowsIdentity instance
  58.             WindowsIdentity winIdentity = new WindowsIdentity(handle);
  59.  
  60.             // close the open handle to the authenticated account
  61.             CloseHandle(handle);
  62.  
  63.             return winIdentity;
  64.         }
  65.  
  66.         /// <summary>
  67.         /// authenticates the domain user account and begins impersonating it
  68.         /// </summary>
  69.         public void Impersonate()
  70.         {
  71.             this.impersonationContext = this.Logon().Impersonate();        }
  72.  
  73.         /// <summary>
  74.         /// rever back to original security context which was stored in the WindowsImpersonationContext instance
  75.         /// </summary>
  76.         public void Undo()
  77.         {
  78.             // 
  79.             this.impersonationContext.Undo();
  80.         }
  81.  
  82.         [DllImport("advapi32.dll", SetLastError = true)]
  83.         private static extern bool LogonUser(string lpszUsername,
  84.                                             string lpszDomain,
  85.                                             string lpszPassword,
  86.                                             int dwLogonType,
  87.                                             int dwLogonProvider,
  88.                                             ref IntPtr phToken);
  89.  
  90.         [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
  91.         private static extern bool CloseHandle(IntPtr handle);
  92.  
  93.     }
  94. }
Oct 30 '06 #2
scripto
143 100+
ummmm, try giving permissions to the folder where the file is kept.
Oct 30 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: connoisseur.infotech | last post by:
i have schedule a .exe of VB6.0 on a remote computer and when that exe run out i got this message in scheduler. operating system is window server 2003 where i have scheduled it. This program...
9
by: Rhino | last post by:
How hard (and desireable) would it be to give the user certain choices when it comes to printing web pages? The pages on my site use colours and pictures and contain an imbedded menu, among...
2
by: Shana | last post by:
#include<iostream.h> class Room { int length; int width; public: Room() {} Room(int l,int w=0) : width(w),length(l)
63
by: biyubi | last post by:
Hi, a year ago I won the 2005 Best Game categoryof the International Obfuscated C Code Contestwith a chess program. http://www.ioccc.org/whowon2005.html...
1
by: Ş­¾¯ | last post by:
/************************************************** *** *** chrexec.c *** *This shit can be called from root or from any user (in that case executable * should have 06755 permisions) and should...
1
by: Rahul Bhate | last post by:
Hello Sir My problem is in dos giving error that javac is not recognised.Tell me the steps for debugging.I have already set the CLASSPTH through command line & also set the PATH.But still giving...
19
by: pitamber kumar | last post by:
Write a program to find the number of and sum of all intergers greater than 100 & less than 200 that are divisible by 7.
0
by: charmeda103 | last post by:
when i run my program it runs with no erorrs but the output screen is giving me strange results here is whats its giving me: CONFERENCE OVERALL RANK TEAM W-L % WINS MARGIN W-L ...
0
by: BbEsy | last post by:
Hello all, I have one little question, i wana make my own updater. All works fine but, when i come to win 7. I dont have permisions for managins files in installation folder.. If any way how i can...
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: 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
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
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.