Adam - The App Developer

Adam - The App Developer

Easy Hacking

Windows

How to Create Batch *.bat Windows Apps.


Create a new txt file and save this after write code as filename.bat)

To shutdown the computer type the below line in the location text field.

shutdown.exe /s /t 00


To restart the computer type the below line in the location text field.

shutdown.exe /r /t 00


To hibernate the computer type the below line in the location text field.

shutdown.exe /h


Click Next, and then for the name of the shortcut type either Shut down, Restart, or Hibernate and then click Finish.

After completing the above steps, double-click the shortcut icon to shut down, restart, or put the computer into hibernation.


Tutorial (German)

Click a script file name to expand and view its source code; click the file name again, or the expanded source code, to hide the source code again.

To view the source code on its own, right-click the file name and choose Open or Open in separate tab or window.

PAUSE


The most obvious way to pause a batch file is of course the PAUSE command. This will stop execution of the batch file until someone presses "any key". Well, almost any key: Ctrl, Shift, NumLock etc. won't work.

This is fine for interactive use, but sometimes we just want to delay the batch file for a fixed number of seconds, without user interaction.


SLEEP


SLEEP was included in some of the Windows Resource Kits.

It waits for the specified number of seconds and then exits.


SLEEP 10

will delay execution of the next command by 10 seconds.


There are lots of SLEEP clones available, including the ones mentioned in the UNIX Ports paragraph at the end of this page.


TIMEOUT


TIMEOUT was included in some of the Windows Resource Kits, but is now a standard command in Windows 7 and 8 (not sure about Vista).

It waits for the specified number of seconds or a keypress, and then exits.

So, unlike SLEEP, TIMEOUT's delay can be "bypassed" by pressing a key.


TIMEOUT 10

or


TIMEOUT /T 10

will delay execution of the next command by 10 seconds, or until a key is pressed, whichever is shorter.


D:>TIMEOUT /T 10


Waiting for  0 seconds, press a key to continue ...

You may not always want to abort the delay with a simple key press, in which case you can use TIMEOUT's optional /NOBREAK switch:


D:>TIMEOUT /T 10 /NOBREAK


Waiting for  0 seconds, press CTRL+C to quit ...

You can still abort the delay, but this requires Ctrl+C instead of just any key, and will raise an ErrorLevel 1.


PING


For any MS-DOS or Windows version with a TCP/IP client, PING can be used to delay execution for a number of seconds.

If specified (-w switch), PING will wait for a number of milliseconds between two pings before giving a time-out.


PING 1.1.1.1 -n 1 -w 60000 >NUL

will delay execution of the next command 60 seconds, provided 1.1.1.1 is not a valid IP address (I previously used -n 60 -w 1000 which should theoretically result in the same delay, but as Greg Hassler pointed out this may be highly inaccurate on some computers).


My previous information that you should PING to localhost using 1 extra ping was incorrect for intervals other than 1 second, as Todd Renzema pointed out to me.

He found out that if the ping does not time out, as is the case when pinging to localhost, the next ping will be about 1 second later, no matter what time-out interval is specified.

To use the time-out specified, ping to a non-existent IP address, and do not add an extra ping. Do not ping to a non-existent host name, since that will only result in a "Unknown host" error message within a second.


And, as Les Ferch pointed out, your computer should be connected to the network for the PING delay to work, otherwise you'll immediately get an error message, and no delay.


With the advance of TCP/IPv6 the command has to include that as well:


PING 127.0.0.1 -n 60 >NUL 2>&1 || PING ::1 -n 60 >NUL 2>&1

Summarizing: probably the safest, though not the most accurate PING based delay uses 127.0.0.1 and ::1, and the standard 1 second ping interval instead of a specified time-out interval, i.e. PING 127.0.0.1 -n 6 || PING ::1 -n 6 for a 5..6 seconds delay.

Create Own Personal Cloud-Server
http://davebennett.tech/create-your-own-personal-cloud-server/
Adam Krause
Cookie settings
X
This site uses cookies to offer you a better browsing experience.
You can accept them all, or choose the kinds of cookies you are happy to allow.
Privacy settings
Choose which cookies you wish to allow while you browse this website. Please note that some cookies cannot be turned off, because without them the website would not function.
Essential
To prevent spam this site uses Google Recaptcha in its contact forms.

This site may also use cookies for ecommerce and payment systems which are essential for the website to function properly.
Google Services
This site uses cookies from Google to access data such as the pages you visit and your IP address. Google services on this website may include:

- Google Maps
Data Driven
This site may use cookies to record visitor behavior, monitor ad conversions, and create audiences, including from:

- Google Analytics
- Google Ads conversion tracking
- Facebook (Meta Pixel)