Running a command, applying changes and other Windows Techniques

If you frequently RUN Windows System Utilities and apply changes to your profile, then you may know most of the tips given here. If you are only starting out, then you definitely need to know these small tips that can make your life easier. These tips constitute a series. Please read all the series posts.


In this article, we will discuss the different ways by which we can RUN a Windows utility. In order to run a program directly (by typing its name in the RUN box) it should be in a folder specified in the PATH variable. We will come to the PATH variable in a later post. While one can always run a program by double clicking on it, there are always easier methods to do it. Using keyboard shortcuts is second nature to anyone who has been working with a computer for a reasonable amount of time.

The easiest and quickest way to run a program or command is to type it directly into the Start Menu of Windows 7. This trick will only work if the item is part of the start menu. For example, you can open the Command Prompt by typing “cmd” and pressing ENTER or you can open Microsoft Word by typing “Office Word” and pressing ENTER. Do remember the functionality is limited and the program that will start will be the first item that appears in the Search.

RUN a command using Quick Search
Running a Command using the Start Menu

Using WIN+R – Run

The most popular of all is the normal RUN dialog box method. You press WIN+R and then type in the command name into the box that appears. You can only run a program which can be found using the PATH system variable. (Type in “echo %PATH%” in a Command Prompt and see for yourself). You need to type the name of the program without the extension (the .exe part)

Running a command using the RUN dialog box.

Using the Command Prompt

You can run any command/program by typing in its name in the command prompt. The command prompt can be opened by typing “cmd” after pressing WIN+R or clicking on the “Command Prompt” icon under “START>>All Programs>>Accessories” The rules that apply for WIN+R applies here too.

Comamnd Prompt
Running a command from the command prompt.

From Task Manager

This is same as the RUN dialog method. You can see a similar box dialog if you open “File>>New Task” under task Manager. You can type in all the things you could do in a WIN+R dialog. Why do you need to use this method then? If Windows Explorer has crashed and you don’t know what to do, press ALT+CTRL+DEL and open the Task Manager. Now go to File>>New Task and type “explorer” and press Enter. Windows Explorer will open again. (Windows explorer is the program that you use to open My Computer or My Documents)

Taskmanager>>File>>RUN
Running a command using Task-manager File menu

How to open TaskManager

TaskManager can be opened using multiple ways.

  1. PressSHIFT+CTRL+ESC
  2. Press ALT+CTRL+DEL and click on the Start Taskmanager button
  3. Type in taskmgr into RUN(WIN+R) dialog
  4. Right click on the Task bar and selectStart Task Manager

If you didn’t already know, you can close any program or system process using Taskmanager.

Restarting Windows Explorer to apply settings

Many of the Windows System changes require you to restart Windows. This can be avoided in most of the cases just by restarting Windows Explorer. Please make sure you have Taskmanager or Command Prompt open while closing windows explorer.

  1. Open Taskmanager
  2. Goto Processes tab
  3. Select explorer.exe from the list and press End Process
  4. Wait a second until it closes
  5. Now goto File>>New task, enter explorer and press ENTER

Another technique can also be used to close Windows Explorer. Press WIN+D to show the desktop. Now bring up the shutdown dialog by pressing ALT+F4. Press ALT+SHIFT+CTRL and click Cancel.

Open Shutdown options dialog box.
Press ALT+CTRL+SHIFT and 'Cancel' in the Shutdown Dialog

any command that can be used in Run box can also be used in the command prompt and the New task option of Taskmanager. In the next post, we will be discussing the programs and commands that can be run using these techniques.

How to shutdown, restart, logoff using command prompt?

Windows provides a builtin command to shutdown, restart as well as logoff a user from the command promptne. This and many other options are provided by the “shutdown” command. In order to find out more options of any command, type :

shutdown /? – command name followed by a forward slash and a question mark.

in Command Prompt ( WIN + R » cmd – here are some more Windows Keyboard shortcuts. You can run any command from Command Prompt or typing the command with full option into the RUN Dialog ( WIN + R ) The main use of all these commands come in batch files and task scheduling. All of these commands are pretty easy to use, please read the article completely before complaining 😉

Basic form of “shutdown”

The most basic form of the command is :

shutdown -OPTION
OR
shutdown /OPTION

Both perform the same thing – execute shutdown command with option OPTION. OPTION can take many values, only the ones of interest to us are mentioned here.

-l – Logs off the current user
-s – Shutdown the computer
-r – Restart the computer

-a – Aborts a current shutdown command execution

-t XX – if this is added with any of the above ones, you can specify after what time ( XX seconds ) the system should execute the OPTION.

A Simple example and a Screenshot

Here the OPTIONs specify that shutdown command should shutdown the command after 120 seconds.

RUNning “shutdown” command with options -s -t 120

shutdown -s -t 120

The screen result will be something like this :

Before shutdown, the logged in user is warned about the event and the time frame.

Canceling a shutdown

If you have given the time parameter -t XX you will have sometime before the command kicks you out. In that time, if you want to cancel the event just type :

shutdown -a -Abort a shutdown

shutdown Aborted – notification

Add a message

You can add a custom message with shutdown so that, instead of the time frame warning, the user will be presented with your message.

shutdown -s -t 120 -c “You are so screwed”

will present the user with the message – “You are so screwed” as below :

Custom message with “shutdown”

More about shutdown on Microsoft KB | Built in parental control in Windows XP

Correction to the list files and folders from a directory to a file

I think you all remember OKTHEN, the one who told us all an easy way to list files and folders in a directory into a file through a context menu. He posted it as a comment. Well last day he commented on the post to correct some mistakes in the comment. Here is his new comment :

sorry i messed up a while back
cmd /c dir %1 /a /b >%1list.txt

would not only be unable to list files in folders with long file names but also it would not be able to output the list.txt to a folder with a long file name in order for it to work with long folder names, u need to use quotes around the %1’s also, if you use >> instead of > It will append to any existing list.txt in the folder you are catalogging instead of replacing the text file with a new one

if you want to append to a pre-existing list.txt when one already exists in the output folder then use:

cmd /c dir “%1? /a /b /s >>”%1?list.txt

or if you want it to replace a possibly pre-existing list.txt in the same output folder every time

cmd /c dir %1 /a /b >%1list.txt

————————————————
if you don’t wanna screw around in regedit
————————————————
then copy the following to a notepad document and then save it (where you can find it to click on) as listfiles.reg (NOTE make sure when u are in the save as dialog box in notepad you must use quotes around “listfiles.reg” otherwise it will loose its .reg extension and be useless)

[Start copy below this line]

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOTFoldershellMake FileList]

[HKEY_CLASSES_ROOTFoldershellMake FileListcommand]
@=”cmd /c dir ”%1” /a /b /s >>”%1”\list.txt”

[End copy above this line]

once the above is saved into a file called “listfiles.reg”
find the file in whatever folder you put it in
Right click on the file, left click on Merge
a box will ask are you sure? Yes/No click Yes

now you have a new command available “Make FileList”
when you right click any folder you will see this option

if you left click on the option it will then create a new file within that folder called list.txt which contains the contents of that folder as it was each time you told it to make a list

i realized awhile back i did not afford for long folder names but only now decided to correct it since i want to use almost the exact same thing to create a context deltree command (for quick erasure of files when i want it without using 1: shift+delete or 2: telling recycle bin to never be active keep files)

I am sorry that after his comment I didn’t check the method he mentioned. Actually his methos is easier. He has made it a lot more easier this time by telling a method to do it by using a reg file.

Hi OKTHEN,
thank you very much. BTW since I don’t know your email or website I can’t contact you. So please send me your contact details if you don’t mind. If you are interested in doing a guest post please contact me..

How to find out all open ports, connections and originating IP addresses

netstat is a command available in both Windows and Unix to analyze local ports that are open and all the connections to those ports. The syntax of the command is very simple.

Netstat in action showing my IP and Ports

In the picture above a verysimple example of seeing the ports and connections is shown. The -ano option tells a – all connections n – do not attempt to resolve name o – show the process ID.
The advantage of resolving name is that you can identify a LAN or Internet connection server easily.

Displays active TCP connections, ports on which the computer is listening, Ethernet statistics, the IP routing table, IPv4 statistics (for the IP, ICMP, TCP, and UDP protocols), and IPv6 statistics (for the IPv6, ICMPv6, TCP over IPv6, and UDP over IPv6 protocols). Used without parameters, netstat displays active TCP connections.
Syntaxnetstat [-a] [-e] [-n] [-o] [-p Protocol] [-r] [-s] [Interval]
Top of pageTop of page
Parameters

-a : Displays all active TCP connections and the TCP and UDP ports on which the computer is listening.

-e : Displays Ethernet statistics, such as the number of bytes and packets sent and received. This parameter can be combined with -s.

-n : Displays active TCP connections, however, addresses and port numbers are expressed numerically and no attempt is made to determine names.

-o : Displays active TCP connections and includes the process ID (PID) for each connection. You can find the application based on the PID on the Processes tab in Windows Task Manager. This parameter can be combined with -a, -n, and -p.

-p Protocol : Shows connections for the protocol specified by Protocol. In this case, the Protocol can be tcp, udp, tcpv6, or udpv6. If this parameter is used with -s to display statistics by protocol, Protocol can be tcp, udp, icmp, ip, tcpv6, udpv6, icmpv6, or ipv6.

-s : Displays statistics by protocol. By default, statistics are shown for the TCP, UDP, ICMP, and IP protocols. If the IPv6 protocol for Windows XP is installed, statistics are shown for the TCP over IPv6, UDP over IPv6, ICMPv6, and IPv6 protocols. The -p parameter can be used to specify a set of protocols.

-r : Displays the contents of the IP routing table. This is equivalent to the route print command.

Interval : Redisplays the selected information every Interval seconds. Press CTRL+C to stop the redisplay. If this parameter is omitted, netstat prints the selected information only once.

/? : Displays help at the command prompt.

Automatically refreshing the connection details (click to enlarge image in a new window)The second image shows the capability of netstat to auto refresh. the interval given is in seconds. the 2 indicates refresh every 2 seconds. This is used to continuously update the screen with the current connection informations. You can use this option to onitor which all connections are occuring at each time and the status of different connections. To abort from the autorefresh mode you can press CTRL + C and return to the normal Command Prompt

TCP View – netstat with GUI

TCPView from Sysinternals (now a part of microsoft) did a good job by giving a user interface to the netstat command. TCP View by default shows the remote connection name also.

TCPView from Sysinternals a screenshotThe user interface is neat and clutter free and the download is extremely small at only 94Kb. You have the option to enable or disable Name resolving from IP. The update speeds are also configurable. The main advantage is that you are shown the process names responsible for all the connections directly in the UI. netstat could only display the PIDs.With a little experince you can start monitoring for outgoing and incoming traffic and control them easily using these tools. To control a connection there are two basic options provided with TCPView – Kill Process (to kill a process responsible for the connection) and Close connection. Both os the tools also show the status of the signal.

How to download videos as mp4 from youtube site

Hide files under other files (merge) using command prompt

Here is how you can hide files from the prying eyes of others. This can be done by using the copy command in Command Prompt. The format of the command to merge files is 

copy /b FILE1.ext+FILE2.ext+….+FILEn.EXT destination.EXT

Copy Command in work

The parameter /b tells the command to consider files as Binary. An example is “copy /b 1.jpg+2.zip 3.jpg” which will produce an image named 3.jpg after merging the image 1.jpg and compressed archive 2.zip The file is now treated as an Image of JPEG type. It’s always better to use two files as this will enable you to recover both the files (else you may need a hex editor to split the files).When you want to open the zipped file change the extension of the merged file from .jpg to .zip (if Windows Zip utility won’t open the file use another archive tool such as WinRAR or WinZIP).

The trick can be done with most of the file types. You will not able to recover the second file by changing the extension if both files are of same type, that is both JPG or both ZIP. A HEX editor can be used to find the header of second file, you may copy the data further onwards to a new file to get the lost file.

These are the screen shots of my merging process

The Image file and the Archive before MergingImage and Archive before merging

Files Merged (check out the file sizes of all the three files )
Merged file after The Archive has been locked under the image

The Image file after merging has been renamed to .rar (extension of second file) and has been opened using WinRAR

renamed and opened

If you use a zip file instead, Windows Compressed Folder manager may not recognize the file but a dedicated Archive tool like WinRAR will be able to open the archive.

Batch files to automate tasks in Windows environment – tutorial

A Batch file is any file with an extension .bat . The batch file is special in the sense that whatever you enter in a batch file, will be run as Commands in Command Prompt one line at a time. The commands will be shown in the prompt as they are run.

Creating and Editing :

Creating and Editing Batch Files in WindowsCreate a batch file named batch.bat in your C:\WINDOWS folder. (take note pad and save the file as Save As batch.bat ). type something like shutdown /? inside the file after opening it in notepad or any other text editor and save the file. Go to Command Prompt START >> All Programs >> Accessories >> Command Prompt and type “batch”. A screen similar to the one shown below will appear. The shutdown /? command will show you a simple help on shutdown command’s options and usage. This is a simple example for using the batch file for automating tasks.

Create and Edit batch file

Working :

When you type “batch” in the command prompt Windows looks for executable files named batch first (.COM and then .EXE) then if both of them are not found Windows searches for a file with name batch and extension bat. So now Windows will have located our batch file. Then every line in the batch file are treated as commands. So we have shutdown /? on the first line. This is executed and the output is shown. The locations where Windows looks for commands are set in the PATH Environment Variable

To prevent showing each command on the command prompt before it is run, just add @echo=OFF to the first line of the batch file.

To create a Batch file Right Click and select NEW»Text Document. Rename it with FILENAME.bat (you must have disabled Hide extensions for known file types in Folder Options ). Now drag it to Notepad and type in the command you want to run, Save it (CTRL+S) and close. Or you can open notepad type the commands and then take File>>Save As and in the name filed give FILENAME.BAT and in the File Type give All Types.

At first you may seem this as non-useful but there are many parameters in command prompt including if, for etc.. which will make this a whole lot useful. I will cover automating the tasks in next part of this tutorial.

How to get your new blog post indexed instantly by Google

Every blog author would be delighted to see your new blog post indexed by Google as soon as you write them. This would be a great moment if you are like me. Last day when I searched this blog through Google and found out that the post I did 2 minutes ago was indexed I decided to know whether I had done anything for it. So the next time I posted I checked I found the same result.


My site indexed with all the new pages

What did I do?

What I did is, I pinged my blog from Google BlogSearch. This will make Google Blog search bot crawl your Blog instantly (in most of the cases). So this will cause the main search engine also to reflect the change. The page will not be cached immediately but you will, in almost all the cases, be indexed. The above screen shot was taken a day or two ago. And the results in Google will include your post too.

Built in parental control in Windows XP – control user login times

(Besides parental control, you can disable access to selected drives easily or even prevent others from copying your files to a USB storage device.)

From Windows Vista onwards, a parental control has been built into the Operating System by Microsoft. This is not the case with Windows XP though. Although there are many good third party software available for this purpose, here I am going to show you how you can add a simple time restriction for user login under Windows XP. The whole thing is very easy despite the documentation – just skip to the topicOur easy way


Time restriction is the most basic forms of parental control. There is a built in tool in Windows XP for the very same purpose. This is hidden under a command line interface though. Do not get taken back by command prompt, the trick is pretty easy.

Open Command Prompt

First you have to open a command prompt windows while you are logged into an administrator account. Press Windows + R to open the run dialog and then type “cmd“. (You can find out more shortcuts in – Keyboard shortcuts for Windows)

Using net user command

In the next step we will use the “net” command available only under command prompt for our purpose. The “net” command is one of the most powerful commands available on Windows. It lets you administer and automate many tasks in Windows. We will only use the sub-part specific to user account control. Here are some some details about the net user command (ignore this and skip to next section to find out the our easy way):

Net user

Adds or modifies user accounts or displays user account information.

Syntax

net user [UserName [Password | *] [options]] [/domain]

net user [UserName {Password | *} /add [options] [/domain]]

net user [UserName [/delete] [/domain]]

Parameters

UserName : Specifies the name of the user account to add, delete, modify, or view. The name of the user account can have as many as 20 characters.

Password : Assigns or changes a password for the user’s account. Type an asterisk (*) to produce a prompt for the password. The password is not displayed when you type it at the password prompt.

/domain : Performs the operation on the domain controller in the computer’s primary domain.

options : Specifies a command-line option. The following table lists valid command-line options that you can use.

You can read more about the command at Microsoft KB : Full options of net user command.

Using the Command

Do not get frightened by all those options. What we need to do is very simple. Just use

net user USER_NAME PASSWORD /times:Su-Sa,12-13;
net user USER_NAME PASSWORD /times:Su-Sa,3-15;Sa,15-16;

The first option restricts the time the user \”USERNAME\” with PASSWORD can log in from 12PM to 1PM on all days (Sunday through Saturday) (use 24 hour clock in the command its easier to read). The second command restricts the user USERNAME’s login time to 3AM to 3PM on all days and on Saturdays, allocates additional time from 3PM to 6PM.

net user USERNAME */PASSWORD /times in action

In the above screen shot, the command is used to restrict the user “limited” to login only from 1PM to 3PM on all week days. The * will make the command prompt for the users password.

Clear all restrictions

To clear all restrictions just type : net user USER_NAME PASSWORD/*] /times:all

Here is a screen shot of the error produced if the user tries to log in during restricted hours.

Error when a program is tried to run as restricted account
Error shown during restricted hours.

This is a brief summary about the net user commands on Microsoft Knowledge Base :

Other notes

Days can be spelled out or abbreviated. Time can be given in increments of 1 hour. You may enter the time in either 12-hour or 24-hour notation. For 12-hour notation, use am, pm, a.m., or p.m. The time can be specified in increments of 1 hour. If you need to specify multiple times for different days you can use” /time:” option many times. If you give “*” instead of PASSWORD, a password prompt will be shown so as not to reveal the password.

Article on MS Knowledge Base | Shutdown your computer using command prompt

Add a context menu option to list all files in a folder and save it as text file

okthen has commented here with an easier way if you know registry :
Go to the Folder tree My Computer\HKEY_CLASSES_ROOT\Folder\shell\ Right Click and select New»Key name the key “List Files and Folders” Now add another key to it named command. Go to the Default on right panel and double click on Default REG_SZ and paste
cmd /c dir %1 /a /b >%1\list.txt
Thanks okthen

Well the title explains it all. What we are going to do is add an option like this to the context menu (Right Click) of all folders. When you click on that the result of a dir command (all files and folders in that Filder) are listed and saved to a file name Listofile.txt in the same Folder. This file is then automatically opened. All this can be done by using simple tools available in windows itself. If you need to know more about batch files please read the . Consider reading it first if you don’t know what a batch file is.

Step 1 : Create a batch file

The required commands saved in a batch fileCreate a batch file named “ListFile.bat” at “C:\Program Files\Mine\” folder (of course you can use any name and any location). Noe Right click on it and select Edit. The file will now be opened in NotePad. Enter the following lines as seen in the screen shot here. This step is common to both methods – using registry and using folderoptions menu. The commands are :

cd %1
dir /a /p /o:gen>listofile.txt
start “List of Files” notepad listofile.txt
exit

First line the batch file accepts the path of directory you clicked and changes the directory – cd to it. %1 is the argument.The second line produces the list of files and directories and redirects (>) to a file in that directory named listofile.txt , “start” starts notepad as a new process independent of the batch file and opens the listofile.txt .If you simply type notepad the process will be child of the batch file the result can be observed if you try it.

Adding an option to folder Menu

Easy way – Folder options

Goto Folder Options and select File types select New to add the new action to folder context menu.

Files listed stored automatically into a text file
In the Actions add List Files and Folders, in the Application used to do the action: add “C:\Program Files\Mine\Listfile.bat” “%1″ including the quotes. The %1 tells Windows to send the Path of the folder to our batch file when List Files and Folders option is selected.
list-files-show-add-folder-option-command.gif

Just restart Windows or Restart Windows Explorer and you will see the added options.

Hard Way – Registry Editing

OK so if you want a brief intro to editing registry please read the previous posts – , . Now Go to the Folder tree My Computer\HKEY_CLASSES_ROOT\Folder\shell\ Right Click and select New»Key name the key “List Files and Folders” Now add another key to it named command. Go to the Default on right panel and double click on Default REG_SZ and paste “C:\Program Files\Mine\Listfile.bat” “%1″ and save it.

Registry Key to be added.

So the adding section is finished both the hard way and the easy way.

Result

Since all the hard work is done now lets go for the piece of cake. Right Click on any folder and select List Files and Folders. You will see the file named Listofiles.txt opened and the list of files inside that. The file is also saved inside the folder you selected.

File produced as the output listofile
This as can be seen is the result produced by dir command. This is really simple but can help us understand and tackle Windows our way. Do experiments with other options also. And if you have any doubts just contact me .

You may also want to know