Im writing a windows batch script and I need to set all the users to a certain password? I know that I can do net user
to see all users on the computer and I can do net user username password
to set the password of a user. But Is there a way to combine these two commands to set all the users to a specific passwords.
1 Answer
Setting several username to the same password is a horrible security practice. It means anyone can log into any account with that password – Ramhound
However, next batch code snippet shows a way how-to get active user list. As soon as you remove ECHO
from 6th line, you can see if it works with net
command (could require administrator privileges and run elevated):
@ECHO OFF
SETLOCAL EnableExtensions
FOR /F "TOKENS=2* delims==" %%G IN ('
wmic USERACCOUNT where "status='OK'" get name/value 2^>NUL
') DO for %%g in (%%~G) do (
ECHO net user %%~g
)
Here the for
loops are
%%G
to retrieve the active username
value;%%g
to remove the ending carriage return in the value returned:wmic
behaviour: each output line ends with0x0D0D0A
(<CR><CR><LF>
) instead of common0x0D0A
(<CR><LF>
).
See Dave Benham's WMIC
and FOR /F
: A fix for the trailing <CR>
problem
Resources (required reading):
- (command reference) An A-Z Index of the Windows CMD command line
- (additional particularities) Windows CMD Shell Command Line Syntax
- (
%~G
special page) Command Line arguments (Parameters) - (
2>NUL
special page) Redirection
FOR /F "TOKENS=*" %F IN (FileList.txt) DO net user %~F password