kill app.path "\**.txt" 删除同级目录的所有txt文本文件
我们提供的服务有:成都网站设计、成都做网站、微信公众号开发、网站优化、网站认证、栾川ssl等。为1000+企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的栾川网站制作公司
获取文件权限干吗?
结合上面那个删除文件,你是想做一个木马类文件捣乱吧?那就不给你获取权限了,给你个遍历文件权限的,如果你能从代码里举一反三写出获取权限来,算你厉害。
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
VB.net(VS2008)里面比C#还好弄,不需要自己加manifest,直接在项目属性的“应用程序”里面点击“查看UAC设置”,在新打开的app.manifest里面把 requestedExecutionLevel level="asInvoker" uiAccess="false" / 替换成 requestedExecutionLevel level="requireAdministrator" uiAccess="false" / 再编译就行了。
'
' 需要添加以下命名空间:
' 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