Batch file - wait time

Posted on 2011-03-06
Last Modified: 2012-05-11
      I need to create a batch file that needs to have two commands in there, but it has to wait for the first command to finish before executing the second command.  I know I can probably put a sleep statement in-between the two, but I cannot be certain that my 'sleep' will always be the same.

Here are the two commands that I need in the batch file

ewfmgr c: -commitanddisable -live

Open in new window

ewfmgr c: -enable

Open in new window

Thank you!
Question by:arunykand
  • 2
  • 2
LVL 16

Accepted Solution

sjklein42 earned 500 total points
ID: 35048875
Putting in a loop like this between the two commands should stall it until the first command takes effect:

sleep 1
ewfmgr c: |findstr DISABLED >nul:
if ERRORLEVEL 1 goto waitForDisabled

Open in new window


Author Comment

ID: 35048917
Will this also ensure that the command window will stay open after it is complete?  I want the window to stay open and wait for the user to close the window.

LVL 16

Expert Comment

ID: 35048978
Here's the whole thing.

First does -commitanddisable.
Then loops until the device shows DISABLED status.
Then enables it.
Then waits for user to type any key to close the window.

ewfmgr c: -commitanddisable -live 

@sleep 1
@ewfmgr c: |findstr DISABLED >nul:
@if ERRORLEVEL 1 goto waitForDisabled

ewfmgr c: -enable


Open in new window


Author Comment

ID: 35049757
Great, thanks!

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

My purpose is to describe the basic concepts of virtual memory as implemented in a modern Windows-based operating system. I will also describe the problems inherent in older systems and how virtual memory solves them. The dark ages - before virtu…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now