Windows timeout Command

This content is 6 years old. Technology changes with time. Keep that in mind as you read this article.

As noted in my last post, I came across two commands I had no idea natively existed in Windows. The previous one is waitfor. This command is timeout. WOW. This would have been nice to have known previous for many of my batch scripts instead of hacking up for loops to simulate a wait timeout. Argh!

TIMEOUT [/T] timeout [/NOBREAK]

Description:
    This utility accepts a timeout parameter to wait for the specified
    time period (in seconds) or until any key is pressed. It also
    accepts a parameter to ignore the key press.

Parameter List:
    /T        timeout       Specifies the number of seconds to wait.
                            Valid range is -1 to 99999 seconds.

    /NOBREAK                Ignore key presses and wait specified time.

    /?                      Displays this help message.

NOTE: A timeout value of -1 means to wait indefinitely for a key press.

Examples:
    TIMEOUT /?
    TIMEOUT /T 10
    TIMEOUT /T 300 /NOBREAK
    TIMEOUT /T -1

Windows Waitfor Command

This content is 6 years old. Technology changes with time. Keep that in mind as you read this article.

I recently discovered a command I didn’t know about (actually 2 commands). I never knew about waitfor command! Man, this would have been useful in some of my remote package pushing scripts. I guess this has been around since Server 2003 days.

WaitFor has two ways of working:

Syntax 1: to send a signal
    WAITFOR [/S system [/U user [/P [password]]]] /SI signal

Syntax 2: to wait for a signal
    WAITFOR [/T timeout] signal

Description:
    This tool sends, or waits for, a signal on a system. When /S is not
    specified, the signal will be broadcasted to all the systems in a
    domain. If /S is specified, then the signal will be sent only
    to the specified system.

Parameter List:
    /S     system         Specifies remote system to send signal to.

    /U     [domain]user  Specifies the user context under which
                          the command should execute.

    /P     [password]     Specifies the password for the given user context.

    /SI                   Sends the signal across the net to waiting machines

    /T     timeout        Number of seconds to wait for signal. Valid range
                          is 1 - 99999. Default is to wait forever for signal.

    signal                The name of the signal to wait for or to send.

    /?                    Displays this help message.

    NOTE: A system can wait for multiple unique signal names.
    The signal name cannot exceed 225 characters and cannot
    contain characters other than a-z, A-Z, 0-9 and ASCII
    characters in the range 128-255.

Examples:
    WAITFOR /?
    WAITFOR SetupReady
    WAITFOR CopyDone /T 100
    WAITFOR /SI SetupReady
    WAITFOR /S system  /U user /P password /SI CopyDone

Tip: Change DNS Server for a Network Adapter via Command Line in Windows

This content is 6 years old. Technology changes with time. Keep that in mind as you read this article.

Just a quick tip/note on changing the DNS server(s) for a network adapter in Windows from the command line.

To do this, you need elevated privileges on a command line (or you can use ‘runas’ from a non-elevated command line and provide administrative credentials).

c:>netsh interface ip set dns "Local Area Connection" static 8.8.8.8

To set it via DHCP you can just issue:

c:>netsh interface ip set dns "Local Area Connection" dhcp

Bulk add TXT DNS Record to Zones in Windows

This content is 6 years old. Technology changes with time. Keep that in mind as you read this article.

Had more than a handful of domains I needed to add TXT record for in Windows DNS (2003). I did it using dnscmd from 2003 Toolkit and command line.

This will enumerate the zones (I search for Primary and exclude reverse):

dnscmd /enumzones | find /I Primary | find /V Rev > zones.txt

After I have a zones.txt file, I then loop through it to add the TXT record.

for /f %x in (zones.txt) do dnscmd . /recordadd %x @ TXT v=spf1 mx -all

A Windows “whereis” Command

This content is 8 years old. Technology changes with time. Keep that in mind as you read this article.

This one-liner (source):

I found this batch script/command on ServerFault *I think*. Very cool little one-liner trick.

@for %%e in (%PATHEXT%) do @for %%i in (%1%%e) do @if NOT "%%~$PATH:i"=="" echo %%~$PATH:i

Example usage:

C:\Users\Rich\Desktop>whereis cmd
C:\Windows\System32\cmd.exe

C:\Users\Rich\Desktop>whereis shutdown
C:\Windows\System32\shutdown.exe

C:\Users\Rich\Desktop>whereis putty

Update: July 21, 2011 So, I discovered: “where” built-in to Windows…

Description: Displays the location of files that match the search pattern. By default, the search is done along the current directory and in the paths specified by the PATH environment variable.

“where” exists in Windows Server 2003 but I also have it natively on Windows Vista and 7.  Not sure which other Windows releases it is included in.