如何在Windows中从C#程序更改文件权限?
我做了一个C#windows应用程序,将搜索在C驱动器中文件夹 用户在文本框中输入,搜索将在用户按下按钮后开始。 的问题是,我得到一个异常告诉我:如何在Windows中从C#程序更改文件权限?
Access To The Path 'C:\Documents and Settings' is Denied
我如何能发现在C盘的任何文件夹/文件(或任何其他驱动器),我没有访问和更改它的权限通过我的C#程序来访问授予的或某事,以便我可以继续我的搜索?
在Linux中有输入chmod,但我不知道有关Windows ..请帮助:)
搜索代码:
string operationSucceeded = "Operation Completed Successfully";
Exception NoFilesFound = new Exception("No File(s) Found In Specified Directory");
List<string> foundFolders = new List<string>();
private void button5_Click(object sender, EventArgs e)
{
try
{
Search_In_For("C:\\", WantedFile_Folder_TextBox.Text);
if (foundFolders == null) throw NoFilesFound;
for (int i = 0; i < foundFolders.Count; i++)
SearchResultsTextBox.Text += (foundFolders[i] + "\n");
MessageBox.Show(operationSucceeded);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
delegate void SearchDelegate(string searchDir, string wanted);
private void Search_In_For(string searchDir, string wanted)
{
string[] foldersInThisDir = Directory.GetDirectories(searchDir);
if (foldersInThisDir.Length == 0) return;
for (int i = 0; i < foldersInThisDir.Length; i++)
if (foldersInThisDir[i].Contains(wanted))
foundFolders.Add(foldersInThisDir[i]);
SearchDelegate sd = new SearchDelegate(Search_In_For);
for (int i = 0; i < foldersInThisDir.Length; i++)
sd(foldersInThisDir[i] , wanted);
}
尝试从Windows资源管理器运行该程序 '作为管理员' 。
没有工作,这实际上没有任何关系, m试图做 – vexe 2012-07-14 14:10:35
好吧,这个链接可能有帮助:http://en.wikipedia.org/wiki/User%5FAccount%5FControl#Requesting%5Felevation – Surfbutler 2012-07-14 14:19:29
http://stackoverflow.com/questions/4986293/access-to-the-path-is-denied-when-using-directory-getfiles – Anirudha 2012-07-14 14:16:55