Escape backslash in net localgroup command - windows

Anyone know how to escape a command like this inside cmd.exe under Windows 7?
net localgroup "COMPANY\Administrators"
it returns:
The syntax of this command is:
NET LOCALGROUP [groupname [/COMMENT:"text"]] [/DOMAIN]
groupname {/ADD [/COMMENT:"text"] | /DELETE} [/DOMAIN]
groupname name [...] {/ADD | /DELETE} [/DOMAIN]
Thanks

No, you don't need to escape domain name because localgroup command can not list all users of a given domain group.
net localgroup will list all users (both local or from domain) that belong to a given local group (a group that exist on your computer). To get a list of all groupnames registered on your domain controller you should use:
net group /domain
Then to see users from one group (in this example a fake group named RD):
net group RD /domain
With standard command line tools you cannot:
List all users that belongs to a group named Administrators (note that a group named Administrators in your computer may not even exist in another computer).
List all domain users with administration privileges in some computer on the domain (you can list only local ones).
See this post for more options (with external addins).

Related

CMD Command for checking if Local User account exists and create if doesn't

I am looking a single line CMD command to check if local user exists & create if it doesn't exist.
I am aware about command to create a user:
"net user UserName Password /ADD"
As well as for checking if the user exists or not:
"net user | find /i UserName"
Though trying to see if there is a way to join these 2 commands to yield the desired result.
Any guidance would be greatly appreciated.
How about using a condition based on whether the user exists?
SET "THEUSER=username"
NET USER "%THEUSER%" 1>NUL 2>&1 || NET USER "%THEUSER%" Password /ADD

How to add a user into a specific domain using CMD?

In Windows 7, let's say I want to create a user in a specific domain using CMD. If the username is user.name, the password is password and the domain is DMN (the domain my computer is currently connected to), what would the command be? I know the syntax for the net user command is
net user [<UserName> {<Password> | *} [<Options>]] [/domain]
but i've attempted the command
net user user.name password /ADD DMN
and it doesn't work.
What should I do? Is there a proper command for this?
Thanks in advance.
When adding a new domain user with NET USER you don't name the domain. The command executes on the current domain as below.
NET USER user.name password /ADD /DOMAIN

Cannot access the cmd through new admin account

I made an admin account using the following command on the cmd:
net localgroup administrators [username] /add
But now whenever I try to access the cmd it says that either the file has not been found or I don't have permission to access the file.
could you clarify?
Are you:
1) Saying you can't run cmd.exe after logging in as a new user?
(IF so, that sounds like an issue for serverfault)
2) saying that you can't add the User you already created to the local group from the CMD?
(If so, have you Tried right clicking and running the CMD as an administrator?)
3) Saying you are trying to create a user and add it using only this one command?
(If so, you cannot do this. You Must create a user first before you can add it to a group. to create a user at the CMD Prompt, you can use the "Net User" Command such as this:
NET USER [UserName] [password] /ADD
NET Localgroup [GroupName] [UserName] /ADD
e.g. Assuming the user you want to add is named "Joe", and you want the password to be "Abcd1234!" you would use the following:
NET USER Joe Abcd1234! /ADD
NET Localgroup Administrators Joe /ADD
)
4) Some other option?
If one through three the above responses should help.

remove user from local administrators group via cmd line when username has space

I am trying to execute a seemingly simple command, however I am having issues because the username has a space in it.
The user is: ad\local workstation admins (under the local administrators group)
The command is: net localgroup administrators ad\local workstation admins /delete
Which returns:
There is no such global user or group: ad\local.
There is no such global user or group: workstation.
There is no such global user or group: admins.
I have tried a different number of variations using quotes and brackets to no avail.
Just protect the user in quotes
net localgroup administrators "ad\local workstation admins" /delete

How to view user privileges using windows cmd?

I am trying to view the user privileges using the command prompt in Windows.
User account & User privileges such as:
SeBatchLogonRight
SeDenyBatchLogonRight
SeInteractiveLogonRight
SeDenyInteractiveLogonRight
SeServiceLogonRight
SeDenyServiceLogonRight
SeNetworkLogonRight
SeDenyNetworkLogonRight
I tried using ntrights but it's not working. I can't use any tool as I am trying to create an automated script for an OS audit.
You can use the following commands:
whoami /priv
whoami /all
For more information, check whoami # technet.
Mark Russinovich wrote a terrific tool called AccessChk that lets you get this information from the command line. No installation is necessary.
http://technet.microsoft.com/en-us/sysinternals/bb664922.aspx
For example:
accesschk.exe /accepteula -q -a SeServiceLogonRight
Returns this for me:
IIS APPPOOL\DefaultAppPool
IIS APPPOOL\Classic .NET AppPool
NT SERVICE\ALL SERVICES
By contrast, whoami /priv and whoami /all were missing some entries for me, like SeServiceLogonRight.
I'd start with:
secedit /export /areas USER_RIGHTS /cfg OUTFILE.CFG
Then examine the line for the relevant privilege. However, the problem now is that the accounts are listed as SIDs, not usernames.
Go to command prompt and enter the command,
net user <username>
Will show your local group memberships.
If you're on a domain, use localgroup instead:
net localgroup Administrators or net localgroup [Admin group name]
Check the list of local groups with localgroup on its own.
net localgroup
Use whoami /priv command to list all the user privileges.

Resources