文件夹的完全控制权限赋给aspnet用户(ntfs,cacls)
2007-02-08 18:49
387 查看
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
using System.DirectoryServices;
using System.Collections;
using System.Diagnostics;
using System.Management;
namespace GrantUserWritableFile
...{
public class GrantUser
...{
private string directoryInstr = "";
private string directoryPrtfl = "";
private string hostName = "";
public string DomainName = "localhost";
private string userName = "";
private string syspath = "";
private string DriverName = "";
public static void Main(string[] args)
...{
GrantUser gu = new GrantUser();
gu.getInfo();
Console.WriteLine("Grant folder to user complited!");
}
public void getInfo()
...{
DirectoryEntry de = new DirectoryEntry("IIS://Localhost/W3SVC/1/ROOT/RPA");
this.directoryInstr = (string)de.Properties["Path"].Value + "/InstrumentInfo/ChartImages";
this.directoryPrtfl = (string)de.Properties["Path"].Value + "/PortfolioView/ChartImages";
//this.directoryInstr = "C:/1";
DriverName = de.Properties["Path"].Value.ToString().Substring(0, 2);
this.hostName = Dns.GetHostName().ToString();
this.userName = "IUSR_" + hostName;
this.syspath = Environment.SystemDirectory + "/";
ManagementObjectSearcher DiskSearch = new ManagementObjectSearcher(new SelectQuery("Select * from Win32_LogicalDisk"));
ManagementObjectCollection moDiskCollection = DiskSearch.Get();
foreach (ManagementObject mo in moDiskCollection)
...{
if ((mo.SystemProperties["FileSystem"].Value.ToString().ToUpper() == "NTFS") && (DriverName == mo.SystemProperties["name"].Value.ToString()))
...{
this.SetFolder(directoryInstr, userName);
this.SetFolder(directoryPrtfl, userName);
}
}
}
public void SetFolder(string PathName,string userName)
...{
//if (Directory.Exists(PathName) == true)
//{
// Directory.Delete(PathName, true);
//}
//Directory.CreateDirectory(PathName);
Process process = new Process();
process.StartInfo.FileName = syspath + "cmd.exe";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = false;
process.Start();
process.StandardInput.WriteLine(String.Format("cacls {0} /t /e /g {1}:f", PathName, userName));
process.StandardInput.WriteLine("exit");
process.WaitForExit();
process.Close();
}
}
}
相关文章推荐
- C#修改文件或文件夹的权限,为指定用户、用户组添加完全控制权限
- C#修改文件或文件夹的权限,为指定用户、用户组添加完全控制权限
- C#修改文件或文件夹的权限,为指定用户、用户组添加完全控制权限
- C#修改文件或文件夹的权限,为指定用户、用户组添加完全控制权限
- C#修改文件或文件夹的权限,为指定用户、用户组添加完全控制权限
- C#修改文件或文件夹的权限,为指定用户、用户组添加完全控制权限
- C#修改文件或文件夹的权限,为指定用户、用户组添加完全控制权限
- C#修改文件或文件夹的权限,为指定用户、用户组添加完全控制权限
- C#修改文件或文件夹的权限,为指定用户、用户组添加完全控制权限
- C#修改文件或文件夹的权限,为指定用户、用户组添加完全控制权限
- SQL Server 2005 中设置某个用户对某一个数据库有完全控制的权限
- 浅析Yii中使用RBAC的完全指南(用户角色权限控制)
- 浅析Yii中使用RBAC的完全指南(用户角色权限控制)
- NTFS权限中完全控制与读写修改的区别
- 在XP中通过NTFS控制文件夹访问权限(zz)
- Windows 下命令行修改文件夹的控制权限 Cacls
- Form认证下,“完全控制”权限用户,创建页面出错
- Yii中使用RBAC完全指南 (用户角色权限控制)
- Yii中使用RBAC完全指南 (用户角色权限控制)
- sharepoint:拥有完全控制权限的用户依然“拒绝访问” -- 金大昊(jindahao)