kill app.path "\**.txt" 刪除同級(jí)目錄的所有txt文本文件
我們提供的服務(wù)有:成都網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站、微信公眾號(hào)開(kāi)發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、欒川ssl等。為1000+企事業(yè)單位解決了網(wǎng)站和推廣的問(wèn)題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的欒川網(wǎng)站制作公司
獲取文件權(quán)限干嗎?
結(jié)合上面那個(gè)刪除文件,你是想做一個(gè)木馬類文件搗亂吧?那就不給你獲取權(quán)限了,給你個(gè)遍歷文件權(quán)限的,如果你能從代碼里舉一反三寫出獲取權(quán)限來(lái),算你厲害。
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,直接在項(xiàng)目屬性的“應(yīng)用程序”里面點(diǎn)擊“查看UAC設(shè)置”,在新打開(kāi)的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
'取得訪問(wèn)控制列表
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