删除注册表有时会AV报警,其实可以用一句代码搞定:
Open "msi.dll" For Binary Lock Read Write As #FreeFile
或者用API也行:
Option Explicit
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Const GENERIC_READ = &H80000000
Private Const OPEN_EXISTING = 3
Private hFile_Msi As Long
Sub LockMsi()
hFile_Msi = CreateFile(GetSystemDir() & "\msi.dll", GENERIC_READ, 0, ByVal 0&, OPEN_EXISTING, 0, 0)
'Debug.Print hFile_Msi
End Sub
Sub UnLockMsi()
If hFile_Msi > 0 Then CloseHandle hFile_Msi
End Sub
Private Function GetSystemDir() As String
Dim n As Long
Dim strPath As String
strPath = String(260, Chr(0))
GetSystemDirectory strPath, Len(strPath)
n = InStr(strPath, Chr(0))
If n <> 0 Then strPath = Left(strPath, n - 1)
GetSystemDir = strPath
End Function
注意:CreateFile需要带完整路径,OpenFile则不用