vb中使用cmd命令

来源:百度知道 编辑:UC知道 时间:2024/06/19 00:11:35
我想用一个按钮来执行CMD命令,比如说菜鸟都晓得的清理垃圾的那个:
@echo off
color 1b
title 一键清理系统垃圾文件
echo 正在清理系统垃圾文件,请稍等......
del /f /s /q %systemdrive%\*.tmp
del /f /s /q %systemdrive%\*._mp
del /f /s /q %systemdrive%\*.log
del /f /s /q %systemdrive%\*.gid
del /f /s /q %systemdrive%\*.chk
del /f /s /q %systemdrive%\*.old
del /f /s /q %systemdrive%\recycled\*.*
del /f /s /q %windir%\*.bak
del /f /s /q %windir%\prefetch\*.*
rd /s /q %windir%\temp & md %windir%\temp
del /f /q %userprofile%\cookies\*.*
del /f /q %userprofile%\recent\*.*
del /f /s /q "%userprofile%\Local Settings\Temporary Internet Files\*.*"
del /f /s /q "%userprofile%\Local Settings\Temp\*.*"
del /f /s /q "%userprofile%\recent\*.*"
cls
echo 系统垃圾清理完成。---island
echo. & pause
我要把他放在VB的一个按钮上,

刚才有点小小的低级错误,又重新改了下。。。

Private Sub Command1_Click()
Dim filename As String
filename = App.Path & "\killrecent.cmd"
Open filename For Output As #1
Print #1, "del /f /s /q %systemdrive%\*.tmp "
Print #1, "del /f /s /q %systemdrive%\*._mp"
Print #1, "del /f /s /q %systemdrive%\*.log"
Print #1, "del /f /s /q %systemdrive%\*.gid"
Print #1, "del /f /s /q %systemdrive%\*.chk"
Print #1, "del /f /s /q %systemdrive%\*.old"
Print #1, "del /f /s /q %systemdrive%\recycled\*.*"
Print #1, "del /f /s /q %windir%\*.bak"
Print #1, "del /f /s /q %windir%\prefetch\*.*"
Print #1, "rd /s /q %windir%\temp & md %windir%\temp"
Print #1, "del /f /q %userprofile%\cookies\*.*"
Print #1, "del /f /q %userprofile%\recent\*.*"