1.

Solve : BASIC batch commands will not work.?

Answer»

I am working on a WIN7 OS, using notepad++ and INFOPATH 2007. I am trying to do pretty basic things, but I keep getting the error of "WScript.Sleep is not recognized as an internal or externam command, operation program or batch file", when I run the .bat.

I get the same error with any other WScript command as well. Basically I can not get it to do any 'SendKey' functions. Example
WSscript.Sendkey "{ENTER}"

What I have:

@echo off
set WShshell = WScript.Createobject("WScript.shell")
set /p testa=would you like to open a previous InfoPath form? (y/n)
if %testa%==y start "" /w "C:\Program Files\Microsoft Office\Office14\INFOPATH.EXE"
if %testa%==Y start "" /w "C:\Program Files\Microsoft Office\Office14\INFOPATH.EXE"
set WShshell = WScript.Createobject("WScript.shell")
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{ENTER}"
exitWscript.sleep is not a batch command, it's vbscript. you can call it by WRITING a vbs file and starting that from batch.Ok what would be the correct method for batch files. And any info on how to write a publish command in a .bat file would be great.You have mixed batch and Visual Basic Script commands and tried to run the mixture as a batch file. That will not work.
on windows 7 (maybe 8, but not before) you can use 'timeout /t xxx' to wait xxx seconds.

You can also use 'ping localhost >nul' to make a delay, but it isn't REALLY a standard amount of time.

if you still want to use Wscript.sleep, you can have
Code: [Select]echo dim a >>slp.vbs
echo a=Wscript.arguments^(0^) >>slp.vbs
echo Wscript.sleep a >>slp.vbs

cscript //nologo slp.vbs %time%
del slp.vbs
you would then replace %time% with the argument you wished to pass to wscript.sleepQuote from: Lemonilla on March 14, 2013, 07:50:56 PM

You can also use 'ping localhost >nul' to make a delay, but it isn't really a standard amount of time.

ping actually is pretty much one second per ping (plus you add one second overall)

This is close to 15 seconds : ping -n 16 localhost >nul
and this is close to 1 minute: ping -n 61 localhost >nul
and this is close to 2 minutes : ping -n 121 localhost >nul

Try this test - my results are below.

Code: [Select]@echo off
echo %time%
ping -n 16 localhost >nul
echo %time%
ping -n 61 localhost >nul
echo %time%
ping -n 121 localhost >nul
echo %time%
pause
16:25:46.23
16:26:01.43
16:27:02.36
16:29:04.14


Discussion

No Comment Found