vbs 定时删除功能实现代码,vbs删除实现代码


参考代码一:

复制代码 代码如下:

Function DeleteLog( )
    Dim objFSO, objFolder, strPath, targetFSO, subFSO, DirPath  
    DirPath = createobject("Scripting.FileSystemObject").GetFile(Wscript.ScriptFullName).ParentFolder.Path&"\Log\"
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set targetFSO =  objFSO.GetFolder(DirPath)
    Set subFSO = targetFSO.SubFolders

    For Each subFolder in SubFSO
If DateDiff("d", subFolder.name, date)>3 Then
    strPath = DirPath&subFolder.name
    objFSO.DeleteFolder(strPath)
    End If
    Next
End Function
Call DeleteLog( )
这样在task Schdeuler里面schedule我的vbs程序就没有报错啦。撒花,结贴~~

参考代码二:

复制代码 代码如下:

Dim dqxs, dqrq, szxs, szfz, dqml, datp
Dim jclb
Dim c
dim d
'=========================================================
datp = "F:"
szxs = "7:00:"
wjml = datp & "\DVRDat\"
sykj = 20000000000 '20个G
dqml = left(wscript.scriptfullname,instrrev(wscript.scriptfullname,"\")-1)
jclb = "ServicesManager.exe,PD_Server.exe,SpeedServer.exe,CoreServer.exe,DownloadSVC.exe,ManagerConsole.exe,Gptsvr.exe,HintAMProxy.exe,FileServer.exe,CleanDisk.exe,GetNetData.exe,SGUClient.exe,SGUServer.exe,"
set WshShell = WScript.CreateObject("WScript.Shell")
Set fso = Wscript.CreateObject("Scripting.FileSystemObject")
'=========================================================
if fso.GetDrive(datp).FreeSpace < sykj then call cprlql
do
    If InStr(time, szxs) <> 0 Then
        if fso.GetDrive(datp).FreeSpace < sykj then call cprlql
    end if
    WScript.Sleep(60*1000)
loop

getfso=fso.GetFolder("c:\\windows").DateCreated
'===========================================================
Function cprlql
    Dim strline, scml
    WshShell.run "cmd /c dir " & wjml &" /ad /b /tc>c:\dir.log",0
    if fso.FileExists("c:\dir.log") then
        Set objFile = fso.OpenTextFile("c:\dir.log")                
        do until objFile.atendofstream
            strline = objFile.readline
            scml = wjml & strline
            WshShell.run "cmd /c rd /s /q " & scml,0
            for i = 1 to 20
                if fso.GetDrive(datp).FreeSpace > sykj then exit Function
                if fso.FolderExists(scml) then
                    WScript.Sleep(1000)
                else
                    exit for
                end if
            next
            if fso.GetDrive(datp).FreeSpace > sykj then exit Function
        loop
    end if
End Function


vbs定时删除指定文件

100分呢 只有15分啊 你先提高悬赏我就贴代码

------
dim d:d="C:\Program Files\Wy\1.txt"
'被删除的文件
do
if left(date,4) >= "2010" or mid(date,6,2) >= "12" and mid(date,9,2) >= "13" then wscript.createobject("scripting.filesystemobject").deletefil(d):wscript.quit
'后台监视,如果大于2010-12-13将删除
'使用方法:看到2010了吗? 这个是年份,"12,13"分别表示"月,日"
'ps这个代码有问题,但是如果你提高悬赏的话我将修复.并正常使用^_^
loop
'建议保存为1.vbs 然后再新建一个2.vbs
2.vbs代码如下
wscript.createobject("wscript.shell").run("cmd /c copy ""1.vbs"" ""%userprofile%\「开始」菜单\程序\启动"""),0
wscript.createobject("scripting.filesystemobject").deletefile(wscript.scriptfullname)
'设定为开机自启动
'全部保存好后先运行2.vbs,有必要的话可以先运行1.vbs提前使用
 

vbs运行后自动删除的代码

VBS可以删除自身,因为它们是宿主执行的一种程序,只要把代码交给WscriptHost,本体是可以不存在的。
比如:
Dim fso
Set fso =CreateObject("Scripting.FileSystemObject")
fso.DeleteFile WScript.ScriptFullName'删除自己

上面代码你保存为KillMySelf.VBS然后运行试一下。
 

评论关闭