.net 拒绝/只读访问可移动驱动器
我想使用ACL拒绝/只读访问可移动驱动器 我搜索并发现我可以使用setsecurityinfo完成 我引用了Msdn和pinvoke.net,但无法成功设置.net 拒绝/只读访问可移动驱动器,.net,.net,我想使用ACL拒绝/只读访问可移动驱动器 我搜索并发现我可以使用setsecurityinfo完成 我引用了Msdn和pinvoke.net,但无法成功设置 c或Vb.net中所需的帮助MSDN中的FileSystemAccessRule类有以下示例: // Removes an ACL entry on the specified file for the specified account. public static void RemoveFileSecurity(strin
c或Vb.net中所需的帮助MSDN中的FileSystemAccessRule类有以下示例:
// Removes an ACL entry on the specified file for the specified account.
public static void RemoveFileSecurity(string fileName, string account,
FileSystemRights rights, AccessControlType controlType)
{
// Get a FileSecurity object that represents the
// current security settings.
FileSecurity fSecurity = File.GetAccessControl(fileName);
// Remove the FileSystemAccessRule from the security settings.
fSecurity.RemoveAccessRule(new FileSystemAccessRule(account,
rights, controlType));
// Set the new access settings.
File.SetAccessControl(fileName, fSecurity);
}
您应该基于此构建特定的解决方案
请记住,您需要是所有者或拥有“更改权限”才能进行这些更改
[DllImport("advapi32.dll", CharSet = CharSet.Unicode)]
私有静态外部单元SetNamedSecurityInfoWString对象名、SE_对象类型ObjectType、安全信息SecurityInfo、IntPtr PsidDowner、IntPtr psidGroup、IntPtr pDacl、IntPtr pSacl
private void Form1_Load(object sender, EventArgs e)
{
SetNamedSecurityInfo ("\\\\.\\K:",SE_OBJECT_TYPE.SE_FILE_OBJECT,SECURITY_INFORMATION.ProtectedDacl, null, null, null, null);
}
private void SetNamedSecurityInfo(string p, object SE_FILE_OBJECT, object DACL_SECURITY_INFORMATION, object NULL, object NULL_5, object paclNew, object NULL_7)
{
throw new Exception("The method or operation is not implemented.");
}
[DllImportAdvapi32.dll,SetLastError=true]
私有静态外部bool convertstringsidtosidstringsid,ref IntPtr Sid
私有枚举seu对象类型
{
SE_未知_对象_类型=0,
SE_文件_对象,
服务,
塞乌打印机,
SE_注册表项,
Seulmshare,
SE_内核_对象,
SE_WINDOW_OBJECT,
你的目标是什么,
所有的一切,
SE_提供程序_定义的_对象,
SE_WMIGUID_对象,SE_注册表_WOW64_32键
}
[标志]私有枚举安全信息:uint
{
所有者=0x00000001,
组=0x00000002,
Dacl=0x00000004,
Sacl=0x00000008,
ProtectedDacl=0x8000000,
ProtectedSacl=0x40000000,
未受保护的ACL=0x20000000,
未受保护的SACL=0x10000000
}
其中k:是可移动驱动器谢谢,但上面的示例仅适用于文件,不适用于卷