China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-13 17:19
中国DOS联盟论坛 » DOS学习入门 & 精彩文章 (教学室) » Questions about NET USER View 3,380 Replies 15
Original Poster Posted 2006-10-09 22:04 ·  新加坡 Verizon通讯公司UUNet互联点
初级用户
Credits 46
Posts 19
Joined 2006-09-28 20:43
19-year member
UID 63949
Status Offline
I want to make a BAT to add a local account, but I don't know how to modify the "password never expires" option in the command line.

My CMD is net user qgp password/add /active:yes /expires:never /passwordchg:no /passw
ordreq:yes

By the way, how to operate if using IF to judge whether the qgp user exists. Thanks.
Floor 2 Posted 2006-10-10 00:02 ·  新加坡 Verizon通讯公司UUNet互联点
初级用户
Credits 46
Posts 19
Joined 2006-09-28 20:43
19-year member
UID 63949
Status Offline
Netuser is a freeware command line / batch program that will rename a user account.

usage: netuser username <settings>

<settings>:

download from here
http://www.jsifaq.com/dl/netuser.zip

/name:newname
/pwnexp:{y|n} sets Password Never Expires

Examples:

netuser Administrator /name:"My Domain Admin"

netuser "John Doe" /name:DoeJ
Floor 3 Posted 2006-10-10 02:54 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline

1、net user qgp password/add /active:yes /expires:never /passwordchg:no /passwordreq:yes

Among them, the part in red is the option to modify that the password never expires. Its value can be never, or a specific date can be specified, meaning it expires on that day, such as 10/10/08.

2、You can use an if judgment to implement checking whether the qgp user exists.

@echo off
for /f %%i in ('net user ^| find "qgp"') do (
if not "%%i#"=="#" echo There is the qpg user. & goto :lxm
)
echo The qgp user does not exist.
:lxm
pause


But this code has certain limitations. If there is also a system account named qgpabc, it will also report that this user exists.
Floor 4 Posted 2006-10-10 06:20 ·  中国 浙江 衢州 电信
银牌会员
★★★
Credits 1,270
Posts 548
Joined 2004-05-31 00:00
22-year member
UID 25754
Gender Male
Status Offline
The functions of this for and if are really powerful. You can't understand them thoroughly without trying them several more times.
Floor 5 Posted 2006-10-10 08:37 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
20-year member
UID 58987
From 湖南.娄底
Status Offline
Two codes to determine if an account exists:


Code that will never go wrong:

@echo off
net user qgp >nul 2>nul && echo The user exists || echo The user does not exist.
pause



Code with certain limitations:

@echo off
set trom=1
for /f "skip=4 tokens=1-3" %%i in ('net user') do (
if not "%%i"=="" if not "%%i"=="The command completed successfully." if "%%i"=="qgp" echo The user exists. & set trom=2
if not "%%j"=="" if "%%j"=="qgp" echo The user exists. & set trom=2
if not "%%k"=="" if "%%k"=="qgp" echo The user exists. & set trom=2
)
if "%trom%"=="1" echo The user does not exist.
pause
Floor 6 Posted 2006-10-10 09:22 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline

Brother pengfei's ideas are indeed broad. The "net user qgp >nul 2>nul" in the first code and the use of "&&" and "||" are quite clever, and the second code is also a relatively novel idea~

Learning——————
Floor 7 Posted 2006-10-10 19:52 ·  新加坡 Verizon通讯公司UUNet互联点
初级用户
Credits 46
Posts 19
Joined 2006-09-28 20:43
19-year member
UID 63949
Status Offline
Originally posted by lxmxn at 2006-10-10 02:54:

1、net user qgp password/add /active:yes /expires:never /passwordchg:no /passwordreq:yes

Among them, the part in red is the option to set the account to never expire, and its ...



Correct that EXPIRES is the account expiration time, not the password expiration option.
Floor 8 Posted 2006-10-10 19:53 ·  新加坡 Verizon通讯公司UUNet互联点
初级用户
Credits 46
Posts 19
Joined 2006-09-28 20:43
19-year member
UID 63949
Status Offline
Brother pengfei, can you explain your first code segment?
Floor 9 Posted 2006-10-10 23:06 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
20-year member
UID 58987
From 湖南.娄底
Status Offline
The first piece of code is very simple, which is to use net user to list users. If the user exists, it will execute successfully; otherwise, it returns 2. Making use of this, we can very accurately judge whether the user exists.

And the algorithm of the second piece of code is to list all user names and then judge whether the user exists. The limitation here is that if the user name has a space, it will prompt that the user does not exist.
Floor 10 Posted 2006-10-11 00:33 ·  新加坡 Verizon通讯公司UUNet互联点
初级用户
Credits 46
Posts 19
Joined 2006-09-28 20:43
19-year member
UID 63949
Status Offline
Pengfei's explanation is too classic.
Floor 11 Posted 2006-10-12 10:02 ·  中国 上海 黄浦区 电信
初级用户
Credits 46
Posts 19
Joined 2006-09-28 20:43
19-year member
UID 63949
Status Offline
@echo off
echo Testing your network...
ping www.google.com -n 2 >nul 2>nul && echo Site1 is online || echo Site1 network down

ping www.go12ogle.com -n 2 >nul 2>nul && echo Site2 is online || echo Site2 network down

Pause

Everyone can use this code for testing.
Floor 12 Posted 2006-10-14 02:43 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
Originally posted by pengfei at 2006-10-10 23:06:
The first piece of code is very simple, which is to use net user to list users. If the user exists, it will execute successfully; otherwise, it returns 2. Using this point, you can very accurately determine whether the user exists.

And the second...


  Hehe, I tried it. I can't create a user with a space character in CMD, but I can in lusrmgr.msc.
  
  It seems that what Windows can do is not necessarily achievable in CMD.``
Floor 13 Posted 2006-10-14 02:44 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
The user name and the full user name are different.

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 14 Posted 2006-10-14 04:13 ·  中国 甘肃 平凉 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
Originally posted by lxmxn at 2006-10-14 02:43:


  Hehe, I tried it. I can't create a user with a space character under CMD, but I can do it in lusrmgr.msc.
  
  It seems that what WIN can do, under CMD...
Can't create one with spaces? “”
Floor 15 Posted 2006-10-14 12:47 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
RE: he200377


  Hehe, thanks for the reminder, forgot that it can also be enclosed in quotes. It seems I haven't done enough testing.
Forum Jump: