Home > Software engineering >  When there is a problem about a VBS code
When there is a problem about a VBS code

Time:10-31

This code if there is a problem,

 
Dim fso
The set of fso=createobject (" scripting. Filesystemobject ")
If fso. FileExists (" c: \ Windows \ system32 \ ConfBackup.zip ") then
Fso. DeleteFile "c: \ Windows \ system32 \ ConfBackup.zip"
End the if

Dim fDeleteFile
The Set fDeleteFile=CreateObject (" scripting. Filesystemobject ")
If fDeleteFile. FolderExists (" c: \ Windows \ system32 \ ConfBackup ") then
FDeleteFile. DeleteFolder "c: \ Windows \ system32 \ ConfBackup"
End the if

Dim fCreateFile
The Set fCreateFile=CreateObject (" scripting. Filesystemobject ")
FCreateFile. CreateFolder "c: \ Windows \ system32 \ ConfBackup"

WScript. Sleep 2000
Dim Backup
The set Backup=createobject (" wscript. Shell ")
Backup. Run CMD/c confBackup. Bat, vbhide

WScript. Sleep 5000

The 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
The Set oShellApp=CreateObject (" Shell. Application ")
The Set oFSO=CreateObject (" Scripting. FileSystemObject ")
'The source folder needs to have a \ on The End
If Right (sSourceFolder, 1) & lt;> "" Then sSourceFolder=sSourceFolder & amp; ""
On the Error Resume Next
'If a target ZIP exists already, delete it
If oFSO. FileExists (sTargetZIPFile) Then oFSO. The DeleteFile sTargetZIPFile, True
IErr=Err. Number
SErrSource=Err. Source
SErrDescription=Err. The Description
On Error GoTo 0
If iErr & lt;> 0 Then
FZip=Array (iErr, sErrSource sErrDescription)
The Exit Function
End the If
On the Error Resume Next
'for the fileheader for a blank zipfile.
OFSO. OpenTextFile (sTargetZIPFile, 2, True), Write "PK" & amp; CRH (5) & amp; CRH (6) & amp; String (18, CRH (0))
IErr=Err. Number
SErrSource=Err. Source
SErrDescription=Err. The Description
On Error GoTo 0
If iErr & lt;> 0 Then
FZip=Array (iErr, sErrSource sErrDescription)
The Exit Function
End the If
On the Error Resume Next
'Start copying files into the zip from the source folder.
OShellApp. NameSpace (sTargetZIPFile). CopyHere oShellApp. The NameSpace (sSourceFolder). The Items
IErr=Err. Number
SErrSource=Err. Source
SErrDescription=Err. The Description
On Error GoTo 0
If iErr & lt;> 0 Then
FZip=Array (iErr, sErrSource sErrDescription)
The Exit Function
End the If
'Because the copying occurs in a separate process, the script will just continue. Run a DO... LOOP to prevent the function
'the from exiting until the file is finished zipping.
Do Until oShellApp. NameSpace (sTargetZIPFile). The Items. The Count=oShellApp. The NameSpace (sSourceFolder). The Items. The Count
WScript. Sleep 1500 'if you don't succeed, increase the number of seconds to
Loop
FZip=Array (0, ""," ")
End the Function
Call fZip (" c: \ Windows \ system32 \ ConfBackup ", "c: \ Windows \ system32 \ ConfBackup.zip")

Dim Delfso
The set Delfso=createobject (" scripting. Filesystemobject ")
Delfso. DeleteFolder "c: \ Windows \ system32 \ ConfBackup"

CodePudding user response:

.
If there is a problem?
Their first run,
to know if you have any questions?If there is a problem, you can ask it..

CodePudding user response:

You the problem of secondary distribution when jammed?

CodePudding user response:

I feel if "c: \ Windows \ system32 " directory does not exist there will be a problem,
  • Related