≡ Menu

Add new user account from command line (CMD)

Adding users from command line is much easier rather than going through UI. It saves lot of time for Windows admins to add users in bulk using CLI commands/script. Net user command  is the one that Windows users can use to manage user accounts, read on to know how to add users from CMD.

To add a new user account on local computer:

net user username password /ADD

Example: To add a new user account with the loginid John and with password fadf24as

net user John fadf24as /ADD

Hide password

If you do not want the password to be visible while adding new user account, you can use ‘*’ as shown below.

C:\>net user /add John *
Type a password for the user: 
Retype the password to confirm:
The command completed successfully.
C:\>

To add a new user account to the domain:

net user username password /ADD /DOMAIN

Note that the command does not include the name of the domain, it automatically adds to the domain the computer belongs to.

Example:

net user John fadf24as /ADD /DOMAIN

Rename a user account

Net use command does not have any switches to rename a user account.  But we can do that using wmic commands. Please check this – Rename user accounts on Windows

Few more advanced uses of net user command.

To set user full name while creating the user account

net user username password /ADD /FULLNAME:"User_Fullname"

To allow user to change password:

net user username password /ADD /PASSWORDCHG:Yes

To restrict user not to change the password:

net user username userpasswd /ADD /PASSWORDCHG:NO

To set account expiry time we can use /EXPIRES switch. This can also be used to set that the account never expires.

To specify if the user must  have a password set we can use /PASSWORDREQ switch. For more information on all net user options, read this – Net user command: syntax and examples

How to create a new administrator account?

An administrator account can’t be created directly.  We first need to create a user account and then add the user to the administrators group.

Errors:

  1. If you don’t have privileges to add new user account to the system, you would get an error like below.
    C:\>net user John /add
    System error 5 has occurred.
    Access is denied.
    C:\>
  2. While adding user to domain, make sure that your computer is connected to the domain. Otherwise it throws up below error.
    C:\>net user testuser testpassword /ADD /DOMAIN
    The request will be processed at a domain controller for domain mydomain.com.
    System error 1355 has occurred.
    The specified domain either does not exist or could not be contacted.

Related Posts:

Remove user from group

Delete directory from command line [Rmdir]

Do you want to delete a directory from Windows command prompt(CMD)? This post explains how to use the command rmdir to delete folders and their contents. You can also find examples for each use case of folder deletion – empty folders, non empty folders, folders with white spaced names etc.

Delete folder from CMD

Run the command rmdir on the folder.

rmdir directoryname

Example:

C:>rmdir emptydir
C:>

How to delete a non empty folder

The simple rmdir does not work for folders having some content.

C:>rmdir nonemptydir
The directory is not empty.

Use /s option to delete the folder contents along with the folder. This deletes all subfolders recursively.

C:>rmdir /S nonemptydir
nonemptydir, Are you sure (Y/N)? y 
C:>

Force delete a folder without confirmation

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

rmdir /Q /S nonemptydir

We can also use ‘rd’ in place of ‘rmdir‘. Both names refer to the same command. This command works on Windows 2000, Windows XP, Server 2003, Vista, Windows 7 and 10.

Deleting directory with white spaces in the name

Rmdir can delete files with whitespaces in the name, you just need to wrap up the folder name in double quotes as shown in the below example.

rmdir /Q /S "folder with spaces in the name"

Delete contents of a directory but keep the directory

The usecase here is to delete all the contents of the directory but keep the parent directory so that we do not need to create it again. rmdir /Q /S does not work here as it deletes the parent directory too. Rather the below commands should do the trick.

forfiles /P directory_path /M * /C "cmd /c if @isdir==FALSE del @file"
forfiles /P directory_path /M * /C "cmd /c if @isdir==TRUE rmdir /S /Q @file"

This works in 2 steps – the first command deletes all files, whereas the second one deletes all subdirectories.

Errors

To delete a directory, you should have appropriate access permissions on the directory. Otherwise rmdir throws ‘Access denied’ error.

TaskKill: Kill process from command line (CMD)

We can kill a process from GUI using Task manager. If you want to do the same from command line., then taskkill is the command you are looking for. This command has got options to kill a task/process either by using the process id or by the image file name.

Kill a process using image name:

We can kill all the processes running a specific executable using the below command.

taskkill /IM executablename

Example:
Kill all processes running mspaint.exe:

c:\>taskkill /IM mspaint.exe
SUCCESS: Sent termination signal to the process "mspaint.exe" with PID 1972.

Kill a process forcibly

In some cases, we need to forcibly kill applications. For example, if we try to to kill Internet explorer with multiple tabs open, tasklist command would ask the user for confirmation. We would need to add /F flag to kill IE without asking for any user confirmation.

taskkill /F /IM iexplore.exe

/F : to forcibly kill the process. If not used, in the above case it will prompt the user if the opened pages in tabs need to be saved.

To kill Windows explorer, the following command would work

C:\>taskkill /F /IM explorer.exe
SUCCESS: The process "explorer.exe" with PID 2432 has been terminated.

The above command would make all GUI windows disappear. You can restart explorer by running ‘explorer’ from cmd.

C:\>explorer

Not using /F option, would send a terminate signal. In Windows 7, this throws up a shutdown dialog to the user.

C:\>taskkill /IM explorer.exe
SUCCESS: Sent termination signal to the process "explorer.exe" with PID 2432.
C:\>

Kill a process with process id:

We can use below command to kill a process using process id(pid).

taskkill /PID  processId

Example:
Kill a process with pid 1234.

taskkill /PID 1234

Kill processes consuming high amount of memory

taskkill /FI "memusage gt value"

For example, to kill processes consuming more than 100 MB memory, we can run the below command

taskkill /FI "memusage gt 102400"

More examples

Sometimes applications get into hung state when they are overloaded or if the system is running with low available memory. When we can’t get the application to usable state, and closing the application does not work, what we usually tend to do is kill the task/process. This can be simply done using taskkill command.

To kill Chrome browser from CMD

Taskkill /F /IM Chrome.exe

Kill Chromedirver from command line

Taskkill /F /IM Chromedriver.exe

To kill firefox browser application

taskkill /F /IM firefox.exe

To kill MS Word application(Don’t do this if you haven’t saved your work)

taskkill /F /IM WinWord.exe

Sometimes, the command window itself might not be responding. You can open a new command window and kill all the command windows

taskkill /F /IM cmd.exe

This even kills the current command window from which you have triggered the command.

Kill Chrome from command line

Chrome is definitely the stable browser compared to other ones and it has been my default browser for several years. But of late I have seen it freezing at times and not responding to user actions. Attempting to shutdown Chrome from task bar ‘Close window’ does not help too. In those situations there’s no option other than forcibly killing Chrome from command prompt. Read on to know how to shutdown chrome browser using taskkill command

Use the below command

 Taskkill /F /IM Chrome.exe

You would see success message like below with this command and all Chrome windows would have disappeared.

C:\>Taskkill /F /IM Chrome.exe
SUCCESS: The process "chrome.exe" with PID 8752 has been terminated.
SUCCESS: The process "chrome.exe" with PID 8780 has been terminated.

Running taskkill without /F option was throwing the below error for me

SUCCESS: Sent termination signal to the process "chrome.exe" with PID 16612.
ERROR: The process "chrome.exe" with PID 17264 could not be terminated.
Reason: This process can only be terminated forcefully (with /F option).

That’s all to kill stuck Chrome application. Let us know in the comments if you had faced such issues with Chrome and if running the above command helps you out.

Find windows OS version from command line

Windows has multiple command line utilities that can help find the version of the Windows OS running on your computer. Below is the list of commands and the information they provide.

  1. Systeminfo command – Windows OS name, version, edition and build number
  2. WMIC command – OS name and version
  3. Ver command – OS version

Find OS Version from command line(CMD)

Systeminfo is a useful command that can dump information about hardware and software running on your computer. Since we are interested in only the OS details, we can filter out other information with the use of findstr command.

systeminfo | findstr /B /C:"OS Name" /C:"OS Version"

Examples:

C:\>systeminfo | findstr /B /C:"OS Name" /C:"OS Version"
OS Name: Microsoft Windows 10 Enterprise
OS Version: 10.0.19042 N/A Build 19042

This command works on Windows 19, Windows and on Server editions also. Find example for Windows 7 below.

systeminfo | findstr /B /C:"OS Name" /C:"OS Version"
OS Name:                   Microsoft Windows 10 Enterprise
OS Version:                10.0.19042 N/A Build 19042

In case of Windows 7 SP1, the output would be slightly different as below.

c:\>systeminfo | findstr /B /C:"OS Name" /C:"OS Version"
OS Name:                   Microsoft Windows 7 Enterprise
OS Version:                6.1.7601 Service Pack 1 Build 7601

If you want to print more details, you may use just ‘OS’ in the findstr search pattern. See example below for Server 2008.

C:\>systeminfo | findstr /C:"OS"
OS Name:                   Microsoft Windows Server 2008 R2 Enterprise
OS Version:                6.1.7600 N/A Build 7600
OS Manufacturer:           Microsoft Corporation
OS Configuration:          Standalone Server
OS Build Type:             Multiprocessor Free
BIOS Version:             IBM -[BWE117AUS-1.05]-, 7/28/2005

Check Windows version using WMIC command

Run the below WMIC command to get OS version and the service pack number(Windows 7 and prior versions).

wmic os get Caption,CSDVersion /value

Example on Windows 10:

c:\>wmic os get Caption,CSDVersion /value
Caption=Microsoft Windows 10 Enterprise
CSDVersion=

Example on Windows 7:

c:\>wmic os get Caption,CSDVersion /value
Caption=Microsoft Windows 7 Enterprise
CSDVersion=Service Pack 1

If you want to find just the OS version, you can use ver command. Open command window and execute ver command. But note that this does not show service pack version.

C:\>ver
Microsoft Windows [Version 10.0.19042.2251]
C:\>

This command does not show version on Windows 7/Windows 10.

Finding version on Windows 7 system

Also Read:

Complete list of Windows CMD commands

How to check if Windows 32 or 64 bit?

There are multiple ways to check whether a Windows computer is running 32-bit OS or of 64-bit one.

Check 32 or 64 bit using WMIC

You can get to know the OS architecture by running the below simple command.

wmic os get OSArchitecture

Example:

c:\>wmic os get OSArchitecture
OSArchitecture
64-bit
c:\>

Using program files folder:

If you have a separate program files folder for x86 applications(named Program Files(x86) ) then we can infer that you are running X64 Windows on your computer.

Few things to note:

  • You can run X64 based Windows OS only on 64-bit computer. If your computer is of 32-bit then the software(Windows OS or any other applications) running on your computer must be of 32-bit only.
  • If your computer is of 64-bit, then it does NOT mean that you have 64-bit OS. You can run either 32-bit OS or 64-bit OS on a 64-bit computer.
  • Even if you are running 64-bit OS, you can still install 32-bit applications on your computer.  All the 32-bit applications are installed to a separate folder named “C:\Programs Files(x86)“.

Get Windows install date

If you ever need to find when was Windows installed on your computer or laptop, then here is a Windows command Systeminfo that can help you with that.

Run the below

  1. Open command prompt
  2. Run the command
    systeminfo | findstr /C:"Install Date"
Command for getting windows installation date

The below example shows install date on my computer

C:\>systeminfo | findstr /C:"Install Date"
Original Install Date:     9/27/2017, 11:53:03 AM

User questions about fixing javac not recognized error

Of all my posts, the one that gets most number of comments is – “Javac is not recognized as internal or external command

Due to heavy incoming comments, I stopped approving them long back to avoid the page become a giant one. However there are still users who’ve been commenting that they were not able to fix the issue. So creating this separate page to receive all such comments and provide help fix the issue. Others can also pitch in and help answer the questions/comments.

Go ahead and use the comments section below to ask your question.

How to Kill process from PowerShell

Powershell provides command Stop-Process to kill a process from command prompt. This command can take in process Id, process name etc and can kill process from CMD.

Powershell command to Kill a process using name

Below is an example command to kill a process using name of the application or image file.

Stop-Process -Name ApplicationName

For example, to kill chrome application using powershell

Stop-process -Name Chrome

Note that this command does not ask for confirmation and straight away kill the running process. If the application is running multiple instances on the computer(For example, multiple firefox windows) it kills each of those processes. If you would like to kill a specific instance, you should use processId argument with Stop-Process command.

Powershell command to kill a process using Id

Stop-process -Id processId

Example:
Below are sequence of commands showing Stop-process killing a specific CMD process.

PS C:\> tasklist | findstr /C:cmd
cmd.exe                       7628 Console                    1      4,444 K
cmd.exe                       9640 Console                    1      3,512 K
cmd.exe                       9352 Console                    1      3,564 K
PS C:\> stop-process -Id 7628
PS C:\> tasklist | findstr /C:cmd
cmd.exe                       9640 Console                    1      3,512 K
cmd.exe                       9352 Console                    1      3,564 K

More examples

Kill all CMD processes running on the computer

Stop-Process -name CMD

Kill windows explorer

Stop-Process -name explorer

Kill putty sessions

stop-process -name putty

Fix WMIC invalid alias verb error

If you use WMIC commands extensively, you would have come across the error – ‘Invalid alias verb’. WMIC error messages are not much self explanatory, so they don’t help in debugging what’s wrong with the command you ran. I encountered this error quite a few times, and upon careful examination I was able to identify what was causing this.

Below was one such instance I got the error

c:\>wmic useraccount where username = 'test1' set PasswordRequired=true
= - Invalid alias verb.

With a quick look, it would not seem like there’s anything wrong with the command. It’s the white space in the where condition that was causing it. So same command with white space removed works perfectly fine.

c:\>wmic useraccount where name='test1' set PasswordRequired=true
Updating property(s) of '\\MYPC\ROOT\CIMV2:Win32_UserAccount.Domain="MYPC",Name="test1"'
Property(s) update successful.

So if you encounter this error, you should check your command for such whitespaces, remove them and try running the command again.