這段代碼是否存在問題,
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"
uj5u.com熱心網友回復:
..是否存在問題?
自己先運行下,就知道有沒有問題啦
如果有問題,就可以再問嘛..
uj5u.com熱心網友回復:
是不是二次分發時卡死的問題?uj5u.com熱心網友回復:
我感覺如果“c:\Windows\system32\”目錄不存在會出現問題。轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/147765.html
標籤:VB基礎類
上一篇:vb存入資料庫資料問題
下一篇:求一個演算法代碼
