How to remove system file attribute

Wednesday, September 30, 2009 0 comments

We can clear system file attribute of a file using the command attrib. Syntax is given below.

attrib -S 

Example:

attrib -S systemfile.exe

The above command will remove system file attribute for the file systemfile.exe

Enable firewall from command line

Firewall configuration can be done from command line using netsh command. To enable firewall run the following command.

netsh firewall set opmode mode=ENABLE


Administrator previliges are required to configure firewall so above command can be run only from admin accounts.



Remove read only attribute of a file from command line

Saturday, September 26, 2009 3 comments

We can clear read-only attribute of a file from command line using attrib command.

attrib -R 

Example:

attrib -R example.doc

The above command will remove read-only attribute for the file example.doc.

How to compress file from command line

We can use compress.exe utility to compress a file from command line. See syntax below.

To coompress a file file1.txt:
compress file1.txt compressedfile1.txt

This tool is available for public download as part of windows server 2003 resource kit. It can be downloaded from the  below location.


http://www.microsoft.com/downloads/details.aspx?FamilyID=9D467A69-57FF-4AE7-96EE-B18C4790CFFD&displaylang=en

Add user to group from command line

Friday, September 25, 2009 0 comments

We can add users to a group from command line too. We can use net localgroup command for this.
For example to add user John to administrators group we can run the below command.
net localgroup administrators John /add

Relevant links:

Delete user from command line

Wednesday, September 23, 2009 0 comments

Use the below commands to delete a user from command line.

To delete a user on a standalone machine:

net user username /DELETE

To delete a user from domain:

net user username /DELETE /DOMAIN

Note that we do not need to specify the domain name here.



Add user from command line

Some times we may want to add users from command line instead of using the UI. For example, if we have to add some 100 users, using a script will save lot of time and manual effort.

To add a user from command line:
net user username userpasswd /ADD

To add a user to the domain:
net user username userpasswd /ADD /DOMAIN

Note that we do not need to specify the domain name here.




Add new users group from command line

Monday, September 21, 2009 0 comments

We can add a new users group from command line too. We can use net localgroup command for this.

For example to add new group with the name say XPUSERS we can run the below command.

net localgroup XPUSERS /add

Reboot computer from command line

We can reboot a machine by using shutdown command from command line.

To reboot the computer:

shutdown -r

To shutdown the computer:
shutdown -s

To abort shutdown:

shutdown -a


Remove user from group using command line

Thursday, September 17, 2009 0 comments

We can remove users from a group using command line too. We can use net localgroup command for this.
For example to remove user John from administrators group we can run the below command.

net localgroup administrators John /delete

Set file attributes from command line

We can use 'attrib' command to set/unset file attributes. Let us see how to use this command to manipulate different file attributes. Take a sample file example.doc
To set archive attribute for the file example.doc:
attrib +a example.doc

To unset archive attribute:
attrib -a example.doc

To set read only attribute:
attrib +r example.doc

To unset read only attribute:
attrib -r example.doc
To make the file hidden :
attrib +h example.doc

To remove the hidden attribute:
attrib -h example.doc

To set system file attribute:
attrib +s example.doc

To unset system file attribute:
attrib -s example.doc


Change my pictures location

Tuesday, September 15, 2009 0 comments

My pictures folder, by default, is located in my documents folder. But in case if you want to move it to some other location you can do it by editing the "My Pictures" registry key under the following node.

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders

Instead of opening registry editor and editing the key manually you can simply run the following command in a command window.

reg.exe add "HKEY_CURRENT_USER\Software\Microsoft\Windows\
CurrentVersion\Explorer\Shell Folders" /v "My Pictures" /t REG_SZ /d "e:\pictures" /f
The above command will make e:\pictures as the location for "My Pictures"

List user names in command prompt

To list the user names having account on the local system you can run the following command.

net user

How to change command window title

We can use the command title to change the namee that appears on the blue bar at the top of command window

c:\>title new_window


The above command will change the title to new_window


Example:
command window initially:



command window after executing the command "title new_window"

How to see the list of mapped network shares

We can use below command to see the list of shares mapped as network drives.

c:\> net use



schedule shutdown from command line

Thursday, September 10, 2009 0 comments

We can schedule shutdown of a machine using the command at. For example, to shutdown the computer at 2PM we can use the following command.
at 14:00 shutdown -s


Map network share to drive from command line

We can map a network share to local drive from command line too. Command is given below.

net use z: \\servername\sharename

The above command maps the drive letter Z: to the network share \\servername\sharename. If the logged in user has credentials to access this network share, the above command completes successfully without asking for any forther information. Otherwise it asks for the user name and password with which the share can be accessed. Upon providing this information, the share will be mapped to the drive Z:

We can also use * instead of Z:. This will automatically pick up the unused drive letter starting from Z:

Launch control panel from command line

We can launch control panel from command line using the command Control.

c:> control

Clear screen in command window

You can use the command cls to clear screen in command prompt.

cmd> cls

Open Add or remove programs wizard from command line

Sunday, September 6, 2009 0 comments

We can  open Add or Remove Programs wizard from command line using appwiz.cpl command.

c:> appwiz.cpl

Or do the following to open the wizard from Run window.

  • Click on Start button
  • Select Run
  • Type appwiz.cpl and press Enter

Open network connections from command line

Run Ncpa.cpl to open network connections from command line. You can also execute ncpa.cpl from Run window to open network connections.

c:> ncpa.cpl

or

  • Click on Start
  • Select Run
  • Type ncpa.cpl and press enter


See list of users from command line

We can see the list of all user accounts created on a computer system using net command.

Just run "net user" from command line and it will print the login names of all the users on the system.

Launch calculator from command line

Saturday, September 5, 2009 0 comments

Use the command calc to launch calculator uitility from command line.

c:> calc


We can also launch calculator by running calc from Run window.

Turn off computer from command line

We can turn off a computer from command line using shutdown command. See the syntax for this below.

Shutdown -s

The above command opens a small window which displays a 30 seconds counter to start shut down of the computer. If we want to abort the shutdown we can run the command shutdown -a from command prompt.

Launch Disk clean up tool from command line

Friday, September 4, 2009 0 comments

We can launch disk cleanup tool from command line using cleanmgr command. Just run cleanmgr from command prompt.

c:> cleanmgr

Open my documents folder from command line

We can use userinit command to open my documents folder in explorer.

,

Launch solitaire game from command line

You can run the command Sol to launch solitaire game from command line.

Launch windows update from command line

Thursday, September 3, 2009 0 comments

We can lauch windows update from command line using wupdmgr.exe utility. Just run Wupdmgr from command line and IE window will opena nd will connect to microsoft update portal automatically.

Open Wordpad from command line

Use the command 'Write' to open Wordpad application from command line. Normally one would assume that the command would be wordpad if it can be launched from command line. But in this case it is Write. No idea why is it so.

Create file from command line

We can create files from command line in two ways. One is using fsutil command and the other way is to use echo command. if you want to write any specific data in the file then use echo command using which you can write the data directly to the file from command line. If you are not bothered about the data in the file but just want to create a file of some specific size then you can use fsutil command.

To create file using echo

echo text-to-be-written-into-the-file  > filename.txt

example:

C:\>echo This is a sample text file > sample.txt

C:\>type sample.txt
This is a sample text file

C:\>

To create file using fsutil command:

fsutil file createnew


example:

C:\data>fsutil file createnew sample2.txt 2000
File C:\data\sample2.txt is created

C:\data>dir
01/23/2009  09:34 PM             2,000 sample2.txt
C:\data>

Search for text files from command line

Wednesday, September 2, 2009 0 comments

On Windows operating system text files usually have .txt extenstion(Yes we can create text files even without .txt extension but unless you have any other special purpose there is no point in doing that). So we can easily find out all the text files in any directory/drive by using dir command.

dir /S *.txt

( /S indicates that search needs to be performed in subfolders too.)

Turn off firewall from command line

Windows firewall can be turned off using the below command.

netsh firewall set opmode mode=DISABLE

An alternative way using user interface is to open firewall.cpl from Run command and then configuring the options in it.

Rename directory from command line

In Renaming files from command line we saw how to rename files using Rename command.   We can use Rename command to rename directories too. See the syntax below.

Rename dir_oldname dir_newname

Example:

G:\data>dir /b

G:\data>mkdir dir1

G:\data>dir /b
dir1

G:\data>rename dir1 dir2

G:\data>dir /b
dir2

G:\data>

Delete directory from command line

We can delete a directory from command line using rmdir command. See syntax below

rmdir directoryname

Examples:


C:\Documents and Settings\Techblogger>rmdir emptydir

C:\Documents and Settings\Techblogger>

C:\Documents and Settings\Techblogger>rmdir nonemptydir
The directory is not empty.

C:\Documents and Settings\Techblogger>rmdir /S nonemptydir
nonemptydir, Are you sure (Y/N)? y

C:\Documents and Settings\Techblogger>

As you can see in the above examples, we need to use /S to delete a non empty directory.

To delete directory in quiemode, without being asked for confirmation, we can use /Q switch.

rmdir /Q /S nonemptydir

Change windows command prompt

Tuesday, September 1, 2009 0 comments

 When you open command window what you would see is like below.

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\Techblogger>

The command prompt is normally displayed as current directory path appended with greater than symbol. There is an environment variable called PROMPT which controls how command prompt should be displayed.

We can check the value of this environment variable using set command.

C:\Documents and Settings\Techblogger>set prompt
PROMPT=$P$G
C:\Documents and Settings\Techblogger>

$P stands for the path of the current direcotory and $G for greater than symbol. Hence the prompt is shown as current directory path followd by a greater than symbol.  Now let' see what other options we have.

 $A   & (Ampersand)
 $B   | (pipe)
 $C   ( (Left parenthesis)
 $D   Current date
 $E   Escape code (ASCII code 27)
 $F   ) (Right parenthesis)
 $G   > (greater-than sign)
 $H   Backspace (erases previous character)
 $L   < (less-than sign)
 $N   Current drive
 $P   Current drive and path
 $Q   = (equal sign)
 $S     (space)
 $T   Current time
 $V   Windows XP version number
 $_   Carriage return and linefeed
 $$   $ (dollar sign)

Using the above codes we can change command prompt display the way we want. See some examples below.

1) To have Windows OS version followed by a $ symbol

C:\Documents and Settings\Techblogger>prompt $V$$
Microsoft Windows XP [Version 5.1.2600]$
Microsoft Windows XP [Version 5.1.2600]$
Microsoft Windows XP [Version 5.1.2600]$

To have ampersand sign followed by date followed by equal sign

C:\Documents and Settings\Techblogger>prompt $A$D$Q

&Thu 01/22/2009=
&Thu 01/22/2009=

Read file from command line

We can read a text file from command line using type command.

Example: Let us se the contents of the file c:\boot.ini

C:\Documents and Settings\Techblogger>type c:\boot.ini
[boot loader]
timeout=30
default=multi(0)disk(0)rdisk(0)partition(2)\WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(2)\WINDOWS="Microsoft Windows XP Home Edition"

Delete file from command line

Del command can be used to delete file(s) from command line. This can be used only to delete files and not for deleting directories. But we can use this do delete all the files in a given directory.

Examples:
To delete a file d:\dir1\data.doc:

c:> del d:\dir1\data1.doc


To delete all the files in direcotry d:\dir1:

c:> del d:\dir1


This will ask the user for confirmation whether he/she really wants to delete all the files in the specified direcory.
To delete the files without asking for confirmation:

c:>del /Q d:\dir1

Rename file from command line

 We can use the built-in command line utility rename to rename a file. Note that this command is just to rename a file keeping it in the same location and can't be used to rename it as a file in a different folder.

Ex:

c:> reaname d:\data\file1.doc file2.doc

After executing the above command we'll have file2.doc in the folder d:\data