Http get windows user

Create a local user or administrator account in Windows 10

You can create a local user account (an offline account) for anyone who will frequently use your PC. The best option in most cases, though, is for everyone who uses your PC to have a Microsoft account.

If needed, the local user account can have administrator permissions; however, it’s better to just create a local user account whenever possible.

Caution: A user with an administrator account can access anything on the system, and any malware they encounter can use the administrator permissions to potentially infect or damage any files on the system. Only grant that level of access when absolutely necessary and to people you trust.

As you create an account, remember that choosing a password and keeping it safe are essential steps. Because we don’t know your password, if you forget it or lose it, we can’t recover it for you.

If you’re using Windows 10, version 1803 and later, you can add security questions as you’ll see in step 4 under Create a local user account. With answers to your security questions, you can reset your Windows 10 local account password. Not sure which version you have? You can check your version.

Create a local user account

Select Start > Settings > Accounts and then select Family & other users. (In some versions of Windows you’ll see Other users.)

Select Add someone else to this PC.

Select I don’t have this person’s sign-in information, and on the next page, select Add a user without a Microsoft account.

Enter a user name, password, or password hint—or choose security questions—and then select Next.

Change a local user account to an administrator account

Select Start > Settings > Accounts .

Under Family & other users, select the account owner name (you should see «Local Account» below the name), then select Change account type.

Note: If you choose an account that shows an email address or doesn’t say «Local account», then you’re giving administrator permissions to a Microsoft account, not a local account.

Under Account type, select Administrator, and then select OK.

Sign in with the new administrator account.

HTTP-запрос методом GET.

Одним из способов, как можно отправить запрос по протоколу HTTP к серверу, является запрос методом GET. Этот метод является самым распространенным и запросы к серверу чаще всего происходят с его использованием.

Самый простой способ, как можно создать запрос методом GET- это набрать URL-адрес в адресную строку браузера.

Если у вас есть желание погрузиться в тему серверного программирования глубже, все мои уроки здесь.

Браузер передаст серверу примерно следующую информацию:

Запрос состоит из двух частей:

1. строка запроса (Request Line)

2. заголовки (Message Headers)

Читайте также:  Windows ошибка hal dll как исправить ошибку

Обратите внимание, что GET запрос не имеет тела сообщения. Но, это не означает, что с его помощью мы не можем передать серверу никакую информацию. Это можно делать с помощью специальных GET параметров.

Чтобы добавить GET параметры к запросу, нужно в конце URL-адреса поставить знак «?» и после него начинать задавать их по следующему правилу:

К примеру, если мы хотим передать серверу два значения, имя пользователя и его возраст, то это можно сделать следующей строкой:

Когда выполнен данный запрос, данные попадают в так называемую переменную окружения QUERY_STRING, из которой их можно получить на сервере с помощью серверного языка веб-программирования.

Вот пример, как это можно сделать на языке PHP.

Конструкция $_GET[«имя_параметра»] позволяет выводить значение переданного параметра.

В результате выполнения этого кода в браузере выведется:

Кстати, переходя по какой-либо ссылке, которая оформлена в HTML вот так:

мы тоже выполняем запрос к серверу методом GET.

Все мои уроки по серверному программированию здесь.

Чтобы оставить сообщение, зарегистрируйтесь/войдите на сайт через:

Или зарегистрируйтесь через социальные сети:

How do you find the current user in a Windows environment?

When running a command-line script, is it possible to get the name of the current user?

15 Answers 15

You can use the username variable: %USERNAME%

Username:

Domainname:

You can get a complete list of environment variables by running the command set from the command prompt.

Just use this command in command prompt

It should be in %USERNAME% . Obviously this can be easily spoofed, so don’t rely on it for security.

Useful tip: type set in a command prompt will list all environment variables.

%USERNAME% is the correct answer in batch and other in Windows environments.

Another option is to use %USERPROFILE% to get the user’s path, like C:\Users\username .

The answer depends on which «command-line script» language you are in.

In the old cmd.exe command prompt or in a .bat or .cmd script, you can use the following:

%USERNAME% — Gets just the username.

%USERDOMAIN% — Gets the user’s domain.

PowerShell

In the PowerShell command prompt or a .ps1 or .psm1 script, you can use the following:

[System.Security.Principal.WindowsIdentity]::GetCurrent().Name — Gives you the fully qualified username (e.g. Domain\Username). This is also the most secure method because it cannot be overridden by the user like the other $Env variables below.

$Env:Username — Gets just the username.

$Env:UserDomain — Gets the user’s domain.

$Env:ComputerName — Gets the name of the computer.

%USERNAME% will get you the username of the currently running process. Depending on how you are running your batch file, this is not necessarily the same as the name of the current user. For example, you might be running your batch file through a scheduled task, from a service, etc.

Here is a more sure way of getting the username of the currently logged on user by scraping the name of the user that started the explorer.exe task:

I use this method in writing batch files for testing.

Since you must include the password in plain text if authentication is required, I will only use it in a completely private environment where other users cannot view it or if a user seeing the password would bear no consequences.

Hope this helps someone out.

Читайте также:  Install xbox 360 controller driver windows 10

It’s always annoyed me how Windows doesn’t have some of more useful little scripting utilities of Unix, such as who/whoami, sed and AWK. Anyway, if you want something foolproof, get Visual Studio Express and compile the following:

And just use that in your batch file.

In most cases, the %USERNAME% variable will be what you want.

However, if you’re running an elevated cmd shell, then %USERNAME% will report the administrator name instead of your own user name. If you want to know the latter, run:

Just type whoami in command prompt and you’ll get the current username.

This is the main difference between username variable and whoami command:

In a standard context, each connected user holds an explorer.exe process: The command [tasklist /V|find «explorer»] returns a line that contains the explorer.exe process owner’s, with an adapted regex it is possible to obtain the required value. This also runs perfectly under Windows 7.

In rare cases explorer.exe is replaced by another program, the find filter can be adapted to match this case. If the command return an empty line then it is likely that no user is logged on. With Windows 7 it is also possible to run [query session|find «>»].

As far as find BlueBearr response the best (while I,m running my batch script with eg. SYSTEM rights) I have to add something to it. Because in my Windows language version (Polish) line that is to be catched by «%%a %%b»==»User Name:» gets REALLY COMPLICATED (it contains some diacritic characters in my language) I skip first 7 lines and operate on the 8th.

Via powershell (file.ps1) I use the following

It returns the name of the user in the «Domain\Username» format. If you just want the username just write

The advantage is that It works with windows 10 windows 8 server 2016. As far as I remember with also other OS like Win7 etc. (not older) . And yeah via batch you can simply use

Not the answer you’re looking for? Browse other questions tagged windows batch-file or ask your own question.

Linked

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.4.16.39093

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Node.Js — Get windows username

I am trying to get the windows username of the machine that is running my node.jS app (the app is always running on a Windows machine).

How can I get the current windows username using Node.Js?

I am trying to find something similar to WindowsIdentity.GetCurrent().Name in C# for node.js, or whoamI command in CMD.

6 Answers 6

Since Node v6 (2016-04), you can just use os.userInfo :

To get the current logged-in username:

I understand that this will not give the client user of a web app as OP asked, but this question is very high in the search results for trying to get the logged in user when running a Node application locally.

Читайте также:  Как узнать частоту обновления монитора windows 10

You can reproduce the \ output of whoamI and WindowsIdentity.GetCurrent() with environment variables in Windows.

If you’d rather use USERPROFILE :

Although node has the built in operating system function os and the os.hostname() to return the host name, you will need to access the client’s hostname in ASP.NET or the language of your choice. You can’t do that in node since it is running on the server side and has nothing to do with the client’s local info.

Look at this question

GET CLIENT HOST NAME IN ASP.NET AKA CLIENT SIDE

SPOON FEED FOR THE LAZY

Someone has created a module called username that does all of the hard work for you.

You use it like

I believe you are stating that you have a Asp.NET application, and would like to use Node.js to determine the current users username, and then submit it to your Asp.NET application.

I do not develop on Windows though from this question I believe this may be stored as an environment variable. process.env is a javascript map / dict of environment variables and likely contains the users username.

Alternatively you can parse it from the users home directory as such :

var path = require(‘path’); var username = path.sep(process.env[‘USERPROFILE’])[2];

The question I linked above implies that USERPROFILE resolves to C:\Users\USERNAME\ . I then split the path and take the 3rd element, being the username.

Again, I do not have a windows machine and could not confirm this. Hope this sets you down the right path though.

Get windows users with C#

How can I get a list of all windows users of the local machine with the usage of .NET (C#) ?

2 Answers 2

Here is a blog post (with code) that explains how to do it:

The author lists the following code (quoted from the above site):

You need to add using System.DirectoryServices at the top of your code. To change machines, you would change the Environment.MachineName to be whatever machine you want to access (as long as you have permission to do so and the firewall isn’t blocking you from doing so). I also modified the author’s code to look at the users group instead of the administrators group.

It depends on what you are really ‘after’. if you are on a windows domain (using active directory) then you can query Active Directory IF active directory is being used to limit the users who are «authorized» to use the local machine.

If your requirements are not as stringent then you can inspect the folders in the system UserProfiles where each folder except Default User and All Users represent a user profile that has logged into the local machine. caution this may include system and/or service accounts.

Not the answer you’re looking for? Browse other questions tagged c# .net windows-users or ask your own question.

Linked

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.4.16.39093

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Оцените статью