关于一段vbs代码时候存在问题
这段代码是否存在问题,--------------------编程问答-------------------- ..
Dim fso
set fso=createobject("scripting.filesystemobject")
if fso.FileExists("c:\Windows\system32\ConfBackup.zip") then
fso.deleteFile "c:\Windows\system32\ConfBackup.zip"
end if
Dim fDeleteFile
Set fDeleteFile = CreateObject("scripting.filesystemobject")
if fDeleteFile.FolderExists("c:\Windows\system32\ConfBackup") then
fDeleteFile.DeleteFolder "c:\Windows\system32\ConfBackup"
end if
Dim fCreateFile
Set fCreateFile = CreateObject("scripting.filesystemobject")
fCreateFile.CreateFolder "c:\Windows\system32\ConfBackup"
WScript.Sleep 2000
dim Backup
set Backup=createobject("wscript.shell")
Backup.run "cmd /c confBackup.bat",vbhide
WScript.Sleep 5000
Function fZip(sSourceFolder,sTargetZIPFile)
'This function will add all of the files in a source folder to a ZIP file
'using Windows' native folder ZIP capability.
Dim oShellApp, oFSO, iErr, sErrSource, sErrDescription
Set oShellApp = CreateObject("Shell.Application")
Set oFSO = CreateObject("Scripting.FileSystemObject")
'The source folder needs to have a \ on the End
If Right(sSourceFolder,1) <> "\" Then sSourceFolder = sSourceFolder & "\"
On Error Resume Next
'If a target ZIP exists already, delete it
If oFSO.FileExists(sTargetZIPFile) Then oFSO.DeleteFile sTargetZIPFile,True
iErr = Err.Number
sErrSource = Err.Source
sErrDescription = Err.Description
On Error GoTo 0
If iErr <> 0 Then
fZip = Array(iErr,sErrSource,sErrDescription)
Exit Function
End If
On Error Resume Next
'Write the fileheader for a blank zipfile.
oFSO.OpenTextFile(sTargetZIPFile, 2, True).Write "PK" & Chr(5) & Chr(6) & String(18, Chr(0))
iErr = Err.Number
sErrSource = Err.Source
sErrDescription = Err.Description
On Error GoTo 0
If iErr <> 0 Then
fZip = Array(iErr,sErrSource,sErrDescription)
Exit Function
End If
On Error Resume Next
'Start copying files into the zip from the source folder.
oShellApp.NameSpace(sTargetZIPFile).CopyHere oShellApp.NameSpace(sSourceFolder).Items
iErr = Err.Number
sErrSource = Err.Source
sErrDescription = Err.Description
On Error GoTo 0
If iErr <> 0 Then
fZip = Array(iErr,sErrSource,sErrDescription)
Exit Function
End If
'Because the copying occurs in a separate process, the script will just continue. Run a DO...LOOP to prevent the function
'from exiting until the file is finished zipping.
Do Until oShellApp.NameSpace(sTargetZIPFile).Items.Count = oShellApp.NameSpace(sSourceFolder).Items.Count
WScript.Sleep 1500'如果不成功,增加一下秒数
Loop
fZip = Array(0,"","")
End Function
Call fZip ("c:\Windows\system32\ConfBackup","c:\Windows\system32\ConfBackup.zip")
Dim Delfso
set Delfso=createobject("scripting.filesystemobject")
Delfso.deleteFolder "c:\Windows\system32\ConfBackup"
是否存在问题?
自己先运行下,就知道有没有问题啦
如果有问题,就可以再问嘛..
--------------------编程问答-------------------- 是不是二次分发时卡死的问题? --------------------编程问答-------------------- 我感觉如果“c:\Windows\system32\”目录不存在会出现问题。
补充:VB , 基础类