十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
kill app.path "\**.txt" 删除同级目录的所有txt文本文件
创新互联专注为客户提供全方位的互联网综合服务,包含不限于成都做网站、网站建设、增城网络推广、小程序制作、增城网络营销、增城企业策划、增城品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;创新互联为所有大学生创业者提供增城建站搭建服务,24小时服务热线:18980820575,官方网址:www.cdcxhl.com
获取文件权限干吗?
结合上面那个删除文件,你是想做一个木马类文件捣乱吧?那就不给你获取权限了,给你个遍历文件权限的,如果你能从代码里举一反三写出获取权限来,算你厉害。
Sub GetFiles(ByVal ParentFolder As String)
Try
Dim sFolders(), sFiles() As String
sFolders = IO.Directory.GetDirectories(ParentFolder)
For Each sFolder As String In sFolders
GetFiles(sFolder)
'Call AddPath("dir", sFolder)
Debug.Print(sFolder)
Application.DoEvents()
Next
sFiles = IO.Directory.GetFiles(ParentFolder)
For Each sFile As String In sFiles
Debug.Print(sFile)
'AddPath("file", sFile)
'lgCount = lgCount + 1
Application.DoEvents()
Next
Catch ex As Exception
End Try
End Sub
举个例子:
先引入命名空间:
Imports System.IO
Imports System.Security.AccessControl
代码:
Dim sec As DirectorySecurity = New DirectorySecurity
Dim rule As FileSystemAccessRule = New FileSystemAccessRule("Administrator", FileSystemRights.Delete, AccessControlType.Allow)
sec.AddAccessRule(rule)
Directory.CreateDirectory("C:\test", sec)
这段代码就是以 Administrator 帐户 在 C:\ 创建 test 文件夹。
'
' 需要添加以下命名空间:
' Imports System.IO
' Imports System.Security.AccessControl
' */
Dim sPath As String = Server.MapPath(文件夹名称字符串)
Directory.CreateDirectory(sPath)
addpathPower(sPath, "ASPNET", "FullControl")
'////////////////////////////////////////////////
Public Sub addpathPower(ByVal pathname As String, ByVal username As String, ByVal power As String)
Dim dirinfo As DirectoryInfo = New DirectoryInfo(pathname)
If (dirinfo.Attributes FileAttributes.ReadOnly) 0 Then
dirinfo.Attributes = FileAttributes.Normal
End If
'取得访问控制列表
Dim dirsecurity As DirectorySecurity = dirinfo.GetAccessControl()
Select Case power
Case "FullControl"
dirsecurity.AddAccessRule(New FileSystemAccessRule(uername,FileSystemRights.FullControl,InheritanceFlags.ContainerInherit,PropagationFlags.InheritOnly,AccessControlType.Allow))
Exit Sub
Case "ReadOnly"
dirsecurity.AddAccessRule(New FileSystemAccessRule(username,FileSystemRights.Read,AccessControlType.Allow))
Exit Sub
Case "Write"
dirsecurity.AddAccessRule(New FileSystemAccessRule(username,FileSystemRights.Write,AccessControlType.Allow))
Exit Sub
Case "Modify"
dirsecurity.AddAccessRule(New FileSystemAccessRule(username,FileSystemRights.Modify,AccessControlType.Allow))
Exit Sub
End Select
dirinfo.SetAccessControl(dirsecurity)
End Sub
vb.net查看文件夹权限方法:
1、右键单击获取权限的文件夹,转到安全Tab。
2、显示了这个文件夹的权限账户。
3、输入对应账户的名称与密码即可查看全部权限信息。