在进入主题之前,必须先告诉大家,在您清空回收站进,系统会自动更改回收站的图标变成空桶图标,所以,进行中若有错误发生,您还必须还原回收站的图标!
清空回收站,我们使用 API SHEmptyRecycleBin Function
还原回收站的图标,则是使用 API SHUpdateRecycleBinIcon Function
在声明区中加入以下声明:
Public Const SHERB_NOCONFIRMATION = &H1
Public Const SHERB_NOPROGRESSUI = &H2
Public Const SHERB_NOSOUND = &H4
Declare Function SHEmptyRecycleBin Lib "shell32.dll" Alias "SHEmptyRecycleBinA" _
(ByVal hwnd As Long, ByVal pszRootPath As String, ByVal dwFlags As Long) As Long
Declare Function SHUpdateRecycleBinIcon Lib "shell32.dll" () As Long
参数说明如下:
hwnd:某一个 Window 的 Handle
pszRootPath:回收站路径(不一定是根目录),如果使用空字串,则表示要清空所有回收站。
dwFlags:0 或是使用以下之常数:
SHERB_NOCONFIRMATION:表示不显示确定窗口
SHERB_NOPROGRESSUI:表示不显示清空回收站的动画窗口 (经检测98原本已不会发生动画)
SHERB_NOSOUND:表示清空回收站之后不发生声音
wys_sans - 副总裁 十级
你那一条代码 有没有想过要是 回收站的文件是其他盘。你就删除不了了。~
Const SHERB_NOCONFIRMATION = &H1
Const SHERB_NOPROGRESSUI = &H2
Const SHERB_NOSOUND = &H4
Private Declare Function SHEmptyRecycleBin Lib "shell32.dll" Alias "SHEmptyRecycleBinA" (ByVal hwnd As Long, ByVal pszRootPath As String, ByVal dwFlags As Long) As Long
Private Sub Command1_Click()
Dim s As Long
' 清空回收站,不确认 要确认 1 改为0
s = SHEmptyRecycleBin(hwnd, "", 1)
End Sub
用 SHEmptyRecycleBin 这个API函数
在窗体上创建一个command ,然后输入下面的代码..
Private Declare Function SHEmptyRecycleBin Lib "shell32" _
Alias "SHEmptyRecycleBinA" _
(ByVal hWnd As Long, _
ByVal pszRootPath As String, _
ByVal dwFlags As Long) _
As Long
Private Sub Command1_Click()
Dim i As Long
i = EmptyBin(True)
End Sub
Private Function EmptyBin(Silent As Boolean, _
Optional hWnd As Long, _
Optional Drive As String) As Long
Dim rc As Long
Dim dwFlags As Long
If IsNumeric(hWnd) = False Then hWnd = 0
dwFlags = SHERB_NOCONFIRMATION + SHERB_NOSOUND
If Silent Then
dwFlags = deflags + SHERB_NOPROGRESSUI
End If
rc = SHEmptyRecycleBin(hWnd, ByVal Drive, dwFlags)
End Function
一条代码:
shell "del C:\recycled\*.* /f /s /q"