Add Windows user from command line - windows

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"

Related

How to run cmd as admin

I use Windows 10 and in cmd I want to use the command
sfc /scannow
Cmd then gives me this message
You must be an administrator running a console session in order to use the sfc utility.
I then try to open cmd by right-clicking and press Run as Administrator.
But then I get this error. How can I solve this?
Firstly, the error is not related to cmd.exe running as admin. You probably have something incorrectly assigned to that specific shortcut.
Below is the correct way of running cmd.exe as Admin on Windows 8 and Windows 10
On your keyboard press windows key and X then select Command Prompt (Admin) from the list.
Alternatively right click on the start button and select the above mentioned.
This allows your to run cmd.exe as administrator. and you can then run
sfc /SCANNOW
Right-click on the Command Prompt icon and select Run as administrator

Running the cmd in windows command line as admin

Am opening windows cmd.exe as administrator and executing an installer(just call installer.exe) and it runs fine. But if I open the cmd.exe in normal mode ( not as administrator) but run the command as user administrator ( runas /profile /user:adminstrator installer.exe) am not able to execute the installer successfully.
The installer unpacks certain files in c:\users\ dir.
The error that I get is :
"Error running java -Dpython.console.encoding=UTF-8 -jar C:\users\<username>/tools/x.jar : Program ended with an error exit code. "
How can I solve this issue? Since am trying to automate executing this installer, opening the cmd.exe as admin is out of question. I would like to run the command as a normal user or if not possible, as an admin.
Am new to Windows. Any help is appreciated.
Thanks
You could create the .bat file with the line you want to run, then follow the procedures listed below to have it automatically run as an administrator.
Right click on the original file and click Create shortcut.
Right click on the shortcut and select the properties option.
Under the shortcut tab, click on the advanced button in the bottom right hand corner.
Check the box that says run as administrator
Click ok, and then ok.
Now when you double click on the batch file shortcut it will run as an administrator. You can delete the original if you wish to.

How to use RunAs Cmd to Launch Explorer, Windows 8

any idea why this is not working?
runas.exe /user:Administrator "cmd /c explorer"
it returns:
Windows cannot find the specified file. You may not have appropriate
permissions.
the following works by itself:
cmd /c explorer
thx!
Answer found here
http://winaero.com/blog/how-to-run-explorer-as-administrator-on-windows-8-1-windows-8-and-windows-7/
"Microsoft does not allow running Explorer as administrator in Windows 8.1/8 (and in Windows 7 too). The solution to run Explorer elevated...
1- take ownership of registry key below.
Right-click, Permissions, Advanced, Owner Change
or, Use Winaero's RegOwnershipEx application, which allows you to take ownership of registry keys
HKEY_CLASSES_ROOT\AppID{CDCBCFCA-3CDC-436f-A4E2-0E02075250C2}
2- rename or delete the value named 'RunAs'.
3- now Restore Ownership (this failed for me done manually-- i could not re-add TrustedInstaller --user not found).
4- at this point, you will be able to run explorer as admin
5- this process does not cleanly exit when you close the Explorer window! You must remember to terminate it every time you elevate Explorer after you are done working in the Explorer window.
Alternate solution: use Winaero's ELE.exe app to start any program as administrator from the command line.
Usually one wants to run as an Administrator to edit a file, or get permissions to delete a file:
To get to the permissions on a file you can right click on it and select Properties. Then select Security. You will see this dialog:
Then Click on Edit and change the permissions for the relevant user (e.g Mike).
You need to have admin privileges to do this, which can be set via User Account Control.
The File Permissions window looks like this:
Edit as required.
I have admin rights but Windows 8.1 still protects some system files (such as the Android studio.exe.vmoptions) and I used the above method to give me write access to the file.
Hope this helps.
You could always open a dos prompt as Administrator then go to the directory in question then do a Explorer . then it will open the location in question as the elevated user.

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