none
VB.net 删除Win7系统帮助文件的问题 RRS feed

  • 问题

  • WIN7系统帮助文件:
    C:\Windows\Help\Windows\en-US
    C:\Windows\Help\Windows\zh-CN

    我想在程序中删除上面2个文件夹下所有帮助文件,删除不了:

         Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

             For Each foundFile As String In My.Computer.FileSystem.GetFiles("C:\Windows\Help\Windows\en-US", FileIO.SearchOption.SearchAllSubDirectories, "*.*")
                 Try
                     System.IO.File.Delete(foundFile)
                 Catch ex1 As Exception
                     Try
                         System.IO.File.SetAttributes(foundFile, IO.FileAttributes.Normal)
                         System.IO.File.Delete(foundFile)
                     Catch ex2 As Exception
                     End Try
                 End Try
             Next

         End Sub

    进去文件夹手动删除时,提示你需要“TrustedInstaller”提供的权限才能对此文件进行更改。

    怎样才能在程序中成功删除上面的文件夹呢?求高手帮忙!!
    2012年8月3日 16:07

全部回复

  • 试试
    <DllImport("advapi32.dll", ExactSpelling:=True, SetLastError:=True)> Function OpenProcessToken(ByVal h As IntPtr, ByVal acc As Integer, ByRef phtok As IntPtr) As Boolean
        End Function
        <DllImport("advapi32.dll", ExactSpelling:=True, SetLastError:=True)> Function AdjustTokenPrivileges(ByVal htok As IntPtr, ByVal disall As Boolean, ByRef newst As TokPriv1Luid, ByVal len As Integer, ByVal prev As IntPtr, ByVal relen As IntPtr) As Boolean
        End Function
        <DllImport("advapi32.dll", SetLastError:=True)> Function LookupPrivilegeValue(ByVal host As String, ByVal name As String, ByRef pluid As Long) As Boolean
        End Function
    这几个提取权限的API或许。。。

    Visual Basic 初学者 望关照!

    2012年8月4日 16:02