#StackBounty: Prevent screen turning off when lid is closed

Bounty: 100

Is there a way to prevent the screen from being turned off when a laptop’s lid is closed? The power-action for closing the lid is already “do nothing”.


Get this bounty!!!

Automated script to renew IP config on network issues

I had been facing an issue recently in my system that the network connection often got lost and the network icon would start showing the yellow icon indicating that no internet connection is available even though the system is connected to the network.

To solve this I had to run the command

IPCONFIG /RENEW

I had to do this every time and many times would realize that the system had been offline for a while.

Started becoming a bummer to me when others needed to access to my system.

I implemented this script and fired it on startup. It performs a simple task

  • Check if google.com is reachable
  • If Not then run IPCONFIG command
  • if the state is not changed even after this command. that means that your system is actually down. therefore stop retrying

Here is the script:

How to get current datetime on Windows command line for using in a filename?

Lets say you want to have a .bat file that zips up a directory into an archive with the current date and time as part of the name, for example, Code_2008-10-14_2257.zip

In a windows console(CMD), the following command helps you get what you need

@echo off
For /f "tokens=2-4 delims=/ " %a in ('date /t') do (set mydate=%c-%a-%b)
For /f "tokens=1-2 delims=/:" %a in ('time /t') do (set mytime=%a-%b)
echo %mydate%_%mytime%
@echo on

echo "Testing 123" >> "testFile_%mydate%_%mytime%.txt"

This would output the filename appended with the desired time format.

Source

Unable to name the file to certain short names on Windows

Today I faced a peculiar issue, where I was trying to create a file named

PRN.java

It was a short code file and needed to be named with this name only.

2016-01-25_2308

The issue in this name is that PRN is a reserved keyword in the CMD execution shell.

Thus the file cannot be renamed to PRN.<extn> where <extn> can be any extension.

From MSDN:

Do not use the following reserved device names for the name of a file:

CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, PRN, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9. Also avoid these names followed immediately by an extension; for example, NUL.txt is not recommended

How to check which application is using a particular port?

Source : http://oolacola.blogspot.com/2009/04/how-to-find-out-which-application-is.html

Let’s say that we are looking for port 80 — IIS, Apache and other web servers listen in port 80, so when you are having problems starting Apache, this technique will be useful. Here is the command.

C:>netstat -aon | findstr 80

-a means list all active connections and their ports. -o means include their process IDs. -n means display the port numbers numerically.

The pipe symbol ( | ) means, that instead of the result of netstat being displayed on the screen, feed it’s result to the findstr process — we are looking specifically for the line which has 0.0:80 — you actually don’t need findstr, but I don’t want to scroll down and hunt down manually which app is using port 80. You might see something like this.

TCP 0.0.0.0:80 0.0.0.0:0 LISTENING 560

Aha! now we know that process 560 is using port 80 (that last column right there, is the process ID), you could press CTRL-ALT-DEL now to show the process window, and manually look up which app has the process ID 560, or you could enter ..

C:>tasklist | findstr 560