Displaying the right username in PowerShell command prompt - windows

When I open PowerShell, I see Delhivery as the username in the command prompt.
I want the PowerShell command prompt to display the username Hemanta like so: PS C:\Users\Hemanta>.
How can I do that?
Inside my users directory, I have the following directories.
I see a directory called Delhivery. Has this anything to do with the user name displayed in the command prompt?
EDIT-1
If I go to user accounts in Control Panel, I see the following:

Related

How can I change my windows display user name in command prompt?

I need to change my PC's cmd user name. Is there any way to do that?
Like currently in cmd I get
C:\Users\User Name>
But I want
C:\Users\User_Name>
You can do it by using the command prompt.
It would help if i could know what your username on windows is, but if we just say it is "User Name" we can craft a command.
So we start with prompt $P "$P" gives us the path so now our output is C:\Users\User Name then we can add "$H" which is a backspace. So if we add 5 of those we can delete " Name". Now our command looks like this prompt $P$H$H$H$H$H and that will give us this output C:\Users\User. Now we just have to add the "_Name". So now the command will look like this prompt $P$H$H$H$H$H_Name and we will have an output that looks like this C:\Users\User_Name. The last thing we have to add is the ">" at the end and you add that with "$G". Now we have our final command which is prompt $P$H$H$H$H$H_Name$G and will give us the output C:\Users\User_Name>. Try to see if you can craft your own command with your username.
To run the command every time you launch cmd you have to make a registry value in Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor called "autorun" (type string) with your command as the value.

Add Windows user from command line

I'm trying to add a new Windows user from the command line using these instructions. I'm just trying to add a regular user at this time. The command I'm entering is
net user /add admin-user admin
I get the following messages:
System error 5 has occurred.
Access is denied.
I am running this from an admin account, and I'm able to create a user by going through the regular settings screens. What am I doing wrong? TIA.
I am pretty sure you are not running your CMD as admin.
You can check this by typing net session as found here.
To run your CMD as admin:
Press the windows key
Type cmd
Right click on the localised name of cmd (command prompt)
Click on "Run as Administrator"

Difference between command line runas and right click Run As

I want to run an application (.exe file) with a specific user while i'm logged in with another user.
The application which I'm invoking is a licensed one and hence can executed by a specific user.
I refereed this post https://superuser.com/questions/105913/run-as-for-a-bat-file and tried 2 different options as suggested by users i.e. using the command line runas command and using Run As from the context menu.
However for me the context menu one worked but not the command line so there is definitely some difference between the two.
How to make the command line runas work same as context menu Run As ?
I tried following command
runas /profile /env /user:MYUSER "Path to my batch file"
runas /user:<localmachinename_or_domainname>\username path_to_bat
Should be all you need.
As a test, try making your bat file to just run "set" and output to a file, so you can verify that you in fact ran it under that user.
also, in your batch (bat) file, you need to treat it like another DOS prompt.
If your just starting a program, just use
start "c:\pathtoprogram.exe"
For my test example you would enter
cmd /c set>C:\test.txt

How to use runas command in windows 2008 r2 server?

I have written a batch file which will call another batch file and delete some files. For this I need to have admin rights. I tried following command...
runas /user:bala#nsc cmd
Enter the password for bala#nsc: xxxxxxx
Even though bala#nsc has admin rights command prompt is getting opened as a simple user rather than administrator.
I guess, I am missing something. Please help me.
Your results aren't what I expected, either. But I've got a few workarounds to suggest.
You could turn off User Account Control.
You could go to Start --> All Programs --> Accessories, then right-click on "Command Prompt" and choose "Run as Administrator."
You could right-click on your batch script and do the same.
You could create a shortcut to either cmd or your batch script on your Desktop, then modify the properties of that shortcut to run as Administrator.
You could add some code to your batch script to check for admin privileges and prompt for escalation if needed.
Turning off UAC would be my choice.

runas command in windows 7

I'm trying to run a batch file as admin. I found that I can use runas command which corresponds sudo command in Linux I think.
I tried
runas /noprofile /user:computername\adminuser "blah.bat start"
But it gives an error, saying :
Logon failure: user account restriction.. (msdos window doesn't allow me to copy anything) is there any way I can run this batch file as admin? Right click doesn't work because I can't include any parameters.
A workaround: You can create a shortcut to the batch file, add a parameter in the shortcut, then right-click to run the shortcut as admin.
Right-click the icon for the command-prompt and choose Run As Administrator. Then run you batch file from that window.
I believe that you can allow or disallow the RunAs command with the registry.
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\Explorer
"HideRunAsVerb"= 1
See Disabling the RunAs Command

Resources