System.UnauthorizedAccessException
Hello There,
i made a simple program to edit the notepad file...using C# ..but i get this error
Code:
System.UnauthorizedAccessException: Access to the path "C:\MyFolder\MySystem\MySystem.INI" is denied.
when i try to run it in a user that has no administrative privileged...
is there any way that it forcely edit the file?..i dnt know what method will be use...right now,i study impersonation but i don't know if this is the solution...
this my code...
Code:
private void Form1_Load(object sender, System.EventArgs e)
{
try
{
ReplaceInFile(@"C:\MyFolder\MySystem\MySystem.INI","58.71.17.62","mlserver.company.com");
ReplaceInFile(@"C:\MyFolder\MySystem\MySystem.INI","192.168.12.100","mlserver.company.com");
ReplaceInFile(@"C:\MyFolder\MySystem\MySystem.INI","mlmysqlchatra","mlserver.company.com");
}
catch (Exception ex)
{
throw ex;
}
}
Code:
static public void ReplaceInFile(string filePath,string searchText,string replaceText)
{
StreamReader reader = new StreamReader(filePath);
string content = reader.ReadToEnd();
reader.Close();
content = Regex.Replace(content,searchText,replaceText);
StreamWriter writer = new StreamWriter(filePath);
writer.Write(content);
writer.Close();
}
hope you can help me..thank you
Re: System.UnauthorizedAccessException
Which operating system are you using?
Re: System.UnauthorizedAccessException
Re: System.UnauthorizedAccessException
So you are saying that you want to edit a file that requires admin privs to edit without having these privs?
Re: System.UnauthorizedAccessException
Quote:
Originally Posted by
Cyb3rH4Xter
So you are saying that you want to edit a file that requires admin privs to edit without having these privs?
yes sir..right now i was thinking of using impersonation...but i dont know if this is the solution...
Re: System.UnauthorizedAccessException
I am sorry but I don't know a way to do that.
Found this thread:
http://stackoverflow.com/questions/1...istrative-user
Where the conclusion is that you can't edit it without the admin rights. It would kinda be a flaw in Windows if you could do that.