Windows commands
All supported versions of Windows (server and client) have a set of Win32 console commands built in.
This set of documentation describes the Windows Commands you can use to automate tasks by using scripts or scripting tools.
Prerequisites
The information that is contained in this topic applies to:
- Windows Server 2019
- Windows Server (Semi-Annual Channel)
- Windows Server 2016
- Windows Server 2012 R2
- Windows Server 2012
- Windows Server 2008 R2
- Windows Server 2008
- Windows 10
- Windows 8.1
Command shell overview
The Command shell was the first shell built into Windows to automate routine tasks, like user account management or nightly backups, with batch (.bat) files. With Windows Script Host you could run more sophisticated scripts in the Command shell. For more information, see cscript or wscript. You can perform operations more efficiently by using scripts than you can by using the user interface. Scripts accept all Commands that are available at the command line.
Windows has two command shells: The Command shell and PowerShell. Each shell is a software program that provides direct communication between you and the operating system or application, providing an environment to automate IT operations.
PowerShell was designed to extend the capabilities of the Command shell to run PowerShell commands called cmdlets. Cmdlets are similar to Windows Commands but provide a more extensible scripting language. You can run Windows Commands and PowerShell cmdlets in Powershell, but the Command shell can only run Windows Commands and not PowerShell cmdlets.
For the most robust, up-to-date Windows automation, we recommend using PowerShell instead of Windows Commands or Windows Script Host for Windows automation.
You can also download and install PowerShell Core, the open source version of PowerShell.
Incorrectly editing the registry may severely damage your system. Before making the following changes to the registry, you should back up any valued data on the computer.
To enable or disable file and directory name completion in the Command shell on a computer or user logon session, run regedit.exe and set the following reg_DWOrd value:
To set the reg_DWOrd value, use the hexadecimal value of a control character for a particular function (for example, 0 9 is Tab and 0 08 is Backspace). User-specified settings take precedence over computer settings, and command-line options take precedence over registry settings.
Command-line reference A-Z
To find information about a specific command, in the following A-Z menu, click the letter that the command starts with, and then click the command name.
Get current logged in user name command line (CMD)
In Windows OS, we can find the current logged in username from windows command line. The logged in user information is stored in environment variables. So just by printing the value in these environment variables we can get to know the login name.
To know the login name of the currently logged in user we can run the below command.
This works on all releases of Windows OS(Windows XP, Server 2003, Windows Vista and Windows 7).
There is another command whoami which tells us the domain name also.
Both of these options to find user name can be useful in batch files to write code in such a way that it works for every user. For example, if your batch file need to access a user specific folder, say Application data, then you can refer the directory as ‘C:\users\%username%\appdata‘.
how to know the current user password in windows 7?
run cmd in admin mode and type net user (user name) (12345)
then your password change to 12345
Use this command:
net user “%username%” “%random%%random%%random%%random%%random%”
Suggestion to use command:
net user “%username%” “%random%%random%%random%%random%%random%”
will change your current users password to something completely random
I don’t think it would be possible to find the password as it is stored in encrypted form and not in plain text. However, there are lots of third party tools to reset a administrator password if you have forgotten the same.
when i go onto command promt it says my username is “user” and say c:/users>user
I HAVE THE SAME PROBLEM. HAVE YOU SOLVE YOUR PROBLEM YET?
The whoami command does not work in Windows XP without the SP2 Support Tools download. The command is not native to the OS. http://www.microsoft.com/en-us/download/details.aspx?id=18546
Can the %username% command be used to determine the user logged into a differnent computer. ex I am at computer x and want to know who is logged on to computer y. I can remote to the c drive using RDP \\computery\c$ I would also like to definively likt to know who is logged on to that computer. Possible?
No, it does not work that way. %username% always shows the user of the current login session. When you run it on remote computer, I am not sure what you would get but it won’t tell you who logged on to the machine.
You can use PSEXEC to run a command on another PC. It can be found in the PS Tools package available for download on many sites.
With System Internal tools (free http://technet.microsoft.com/en-us/sysinternals/bb897545.aspx )
psloggedon \\targetComputer
or
psloggedon \\192.167.0.0
Is it possible to get current User Name when it’s an AD where each user has an ID?
For example, if I run whoami or %username% I get “XX00000” but I want to get “Name SecondName”. I know windows has this info because I see my full name in Start Menu (Win 7).
Thanks
net user %username% for accounts stored in local or net user %username% /domain for accounts stored on domain.
you know this answer…?… anyone please let me know solution for georges’ question.. thanks in advance..
I would also really like a solution for this
If you are asking to find the full name or Surname run this as administrator.
net user
It will show you all the information about that user, full name, logon time, the group this user belongs to, the time it is allowed to login all of that.
When I run whoami from the cmdline I get my username. However I want to find my username from within SQL Server. If I shell out and run whoami I get the sql service user . Any ideas?
what username lets you look at the history
what does it mean by username
Please show screen shot
I have 2 accounts one for me and one for my nephews and nieces so I forgot my password because it makes me change it every other month it seems like and idk why… but I looked up a way to change it by going into the command prompts but it’s only giving me the kids for net user it says mine doesn’t exist I could use some help asap
I need to find my administrator account password when its logged in so is there way i can do it from cmd to find my password without changing it ?
does we have a vraiable like %username% for user group name ?
query user query user
Область применения: Windows Server (половина ежегодного канала), Windows Server 2019, Windows Server 2016, Windows Server 2012 R2, Windows Server 2012 Applies to: Windows Server (Semi-Annual Channel), Windows Server 2019, Windows Server 2016, Windows Server 2012 R2, Windows Server 2012
Отображает сведения о пользовательских сеансах на удаленный рабочий стол сервере узла сеансов. Displays information about user sessions on a Remote Desktop Session Host server. С помощью этой команды можно определить, вошел ли конкретный пользователь на конкретный сервер узла сеансов удаленный рабочий стол. You can use this command to find out if a specific user is logged on to a specific Remote Desktop Session Host server. Эта команда возвращает приведенные ниже сведения. This command returns the following information:
Имя пользователя Name of the user
Имя сеанса на удаленный рабочий стол сервере узла сеансов Name of the session on the Remote Desktop Session Host server
Идентификатор сеанса Session ID
Состояние сеанса (активно или отключено) State of the session (active or disconnected)
Время простоя (количество минут с момента последнего нажатия клавиши или перемещения мыши в сеансе) Idle time (the number of minutes since the last keystroke or mouse movement at the session)
Дата и время входа пользователя Date and time the user logged on
Чтобы узнать о новых возможностях последней версии, см. статью новые возможности службы удаленных рабочих столов в Windows Server. To find out what’s new in the latest version, see What’s New in Remote Desktop Services in Windows Server.
Синтаксис Syntax
Параметры Parameters
Параметр Parameter | Описание Description |
---|---|
Указывает имя входа пользователя, которому необходимо выполнить запрос. Specifies the logon name of the user that you want to query. | |
Указывает имя сеанса, с которым необходимо выполнить запрос. Specifies the name of the session that you want to query. | |
Указывает идентификатор сеанса, к которому необходимо выполнить запрос. Specifies the ID of the session that you want to query. | |
/server: /server: | Указывает удаленный рабочий стол сервер узла сеансов, к которому требуется выполнить запрос. Specifies the Remote Desktop Session Host server that you want to query. В противном случае используется текущий сервер узла сеансов удаленный рабочий стол. Otherwise, the current Remote Desktop Session Host server is used. Этот параметр является обязательным только при использовании этой команды с удаленного сервера. This parameter is only required if you’re using this command from a remote server. |
/? /? | Отображение справки в командной строке. Displays help at the command prompt. |
Комментарии Remarks
Чтобы использовать эту команду, необходимо иметь разрешение на полный доступ или специальное разрешение доступа. To use this command, you must have Full Control permission or special access permission.
Если вы не укажете пользователя, используя параметры , или SessionID , возвращается список всех пользователей, вошедших в систему на сервере. If you don’t specify a user using the , , or sessionID parameters, a list of all users who are logged on to the server is returned. Кроме того, можно также использовать команду запросить сеанс для вывода списка всех сеансов на сервере. Alternatively, you can also use the query session command to display a list of all sessions on a server.
Когда пользователь запроса возвращает сведения, (>) перед текущим сеансом отображается символ «больше чем». When query user returns information, a greater than (>) symbol is displayed before the current session.
Примеры Examples
Чтобы отобразить сведения обо всех пользователях, вошедших в систему, введите: To display information about all users logged on the system, type:
Чтобы отобразить сведения о пользователе User1 на сервере Server1, введите: To display information about the user USER1 on server Server1, type:
Windows command find user
Searches for a string of text in a file or files, and displays lines of text that contain the specified string.
Syntax
Parameters
Parameter | Description |
---|---|
/v | Displays all lines that don’t contain the specified . |
/c | Counts the lines that contain the specified and displays the total. |
/n | Precedes each line with the file’s line number. |
/i | Specifies that the search is not case-sensitive. |
[/off[line]] | Doesn’t skip files that have the offline attribute set. |
Required. Specifies the group of characters (enclosed in quotation marks) that you want to search for. | |
[ :][ |
]
Remarks
If you don’t use /i, this command searches for exactly what you specify for string. For example, this command treats the characters a and A differently. If you use /i, however, the search becomes non-case-sensitive, and it treats a and A as the same character.
If the string you want to search for contains quotation marks, you must use double quotation marks for each quotation mark contained within the string (for example, «»This string contains quotation marks»»).
If you omit a file name, this command acts as a filter, taking input from the standard input source (usually the keyboard, a pipe (|), or a redirected file) and then displays any lines that contain string.
You can type parameters and command-line options for the find command in any order.
You can’t use wildcards (* and ?) in file names or extensions that you specify while using this command. To search for a string in a set of files that you specify with wildcards, you can use this command within a for command.
If you use /c and /v in the same command line, this command displays a count of the lines that don’t contain the specified string. If you specify /c and /n in the same command line, find ignores /n.
This command doesn’t recognize carriage returns. When you use this command to search for text in a file that includes carriage returns, you must limit the search string to text that can be found between carriage returns (that is, a string that is not likely to be interrupted by a carriage return). For example, this command doesn’t report a match for the string tax file if a carriage return occurs between the words tax and file.
Examples
To display all lines from pencil.ad that contain the string pencil sharpener, type:
To find the text, «The scientists labeled their paper for discussion only. It is not a final report.» in the report.doc file, type:
To search for a set of files, you can use the find command within the for command. To search the current directory for files that have the extension .bat and that contain the string PROMPT, type:
To search your hard disk to find and display the file names on drive C that contain the string CPU, use the pipe (|) to direct the output of the dir command to the find command as follows:
Because find searches are case-sensitive and dir produces uppercase output, you must either type the string CPU in uppercase letters or use the /i command-line option with find.