Hi,
You can use
WScript.Sleep from your VBScript Custom Action through the following hack:
1. Your VBScript CA will create a temporary file (with a .vbs extension).
2. The CA will write
WScript.Sleep interval in the temporary file created previously.
3. The CA will launch the temporary .vbs file using the command
wscript.exe TempFile.tmp.vbs
4. The CA will delete the temp .vbs file.
The
Delay and
DelayHelper functions below illustrate the above method, while the
DelayTest function (it can be added as a Custom Action) illustrates how the Delay function can be used.
Code: Select all
Function DelayTest()
MsgBox "Delaying for 5 seconds..."
Delay(5000)
MsgBox "Done!"
End Function
Function Delay(interval)
Dim delayCmd
delayCmd = "WScript.Sleep " & CStr(interval)
DelayHelper(delayCmd)
End Function
Function DelayHelper(strContent)
Const TemporaryFolder = 2
Dim fso, WshShell
Dim tempFolder, tempName, tempFullPath, tempFile
Dim strCmd, ret
Set fso = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
Set tempFolder = fso.GetSpecialFolder(TemporaryFolder)
tempName = fso.GetTempName
tempFullPath = fso.BuildPath(tempFolder, tempName)
Set tempFile = fso.CreateTextFile(tempFullPath, True)
tempFile.WriteLine(strContent)
tempFile.Close
' append a vbs extension
fso.MoveFile tempFullPath, tempFullPath & ".vbs"
tempFullPath = tempFullPath & ".vbs"
' execute the temp vbs file using the wscript interpreter
strCmd = "wscript.exe " & chr(34) & tempFullPath & chr(34)
' MsgBox strCmd
ret = WshShell.Run(strCmd, 1, true)
' delete the temp file
Set tempFile = fso.GetFile(tempFullPath)
tempFile.Delete
End Function
Hope this helps.
Regards,
Ionut