Hopefully "ScriptingTipsAndTricks" helps you with your batch file or vbscript scripting :-)
[Bottom][Contents][Prev]: SetChar() - sets up BEEP, TAB characters etc[Next]: String Replacement - case sensitive substitution of  all or part of a string
\->Batch Files->SleepSeconds() - delay processing for the specified number of seconds

SleepSeconds() [delay processing for the specified number of seconds].cmd

The batch file sample below contains VBSCRIPT (is created at run time) imbedded into it.

The "VBS4CMD.VBS" script was used to turn the tested VBSCRIPT into the batch file code to create it. That code was further tweeked.

If you want to change the code its probably easiest to let the batch file create the code and comment out the deletion. You will then be able to test and improve the code before running it through "VBS4CMD.VBS" again.

Depending on your code you may want to create the VBS once and use many times or create each time.

[anchor]

The Code for: "SleepSeconds() [delay processing for the specified number of seconds].cmd"

This is the example, a shortcut was installed to this code :

@echo off
::@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
:: $Header:   C:/DBAREIS/Projects.PVCS/Win32/ScriptingTipsAndTricks/EXAMPLE[cmd].SleepSeconds() [delay processing for the specified number of seconds].cmd.pvcs   1.0   11 Jul 2014 19:31:02   USER "Dennis"  $
::@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
setlocal

echo [%date% %time%] Creating the VBSCRIPT and executing it to wait for 3 seconds...
     call :SleepSeconds 3
echo [%date% %time%] Finished the 3 second wait...
goto :EOF


::++++++++++++++++++++++++++++++++++++++++++
:SleepSeconds
::++++++++++++++++++++++++++++++++++++++++++ v14.073
    set Wait4Seconds=%~1
    set          VBS=%TEMP%\SleepSeconds.VBS
    if exist "%VBS%" goto AlreadyExistsJustSleep
        echo Building the sleep VBSCRIPT: "%VBS%"
        echo on error resume next                                         > "%VBS%"
        echo dim Seconds : Seconds = 10 : Seconds = wscript.arguments(0) >> "%VBS%"
        echo wscript.echo "Sleeping for " ^& Seconds ^& " seconds..."    >> "%VBS%"
        echo wscript.sleep Seconds * 1000                                >> "%VBS%"
        echo wscript.quit(0)                                             >> "%VBS%"
    :AlreadyExistsJustSleep
    cscript.exe //NoLogo "%VBS%" %Wait4Seconds%
    goto :EOF

Please note that that I am not trying to show how great I am by producing batch files 9,000 characters long on one line that no one will understand or be able to debug when they go wrong. I am going out of my way to comment the code and make it verbose so beginners and advanced users will both benefit. I don't claim to be an expert that knows everything, if I'm wrong or make a mistake then please contact me and let me know :-)


Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.Please email me any feedback, additional information or corrections.
See this page online (look for updates)

[Top][Contents][Prev]: SetChar() - sets up BEEP, TAB characters etc[Next]: String Replacement - case sensitive substitution of  all or part of a string


ScriptingTipsAndTricks© is (C)opyright Dennis Bareis 2003-2008 (All rights reserved).
Sunday September 07 2014 at 12:50pm
Visit ScriptingTipsAndTricks's Home Page
Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.