中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-13 15:52
47,811 topics / 349,897 posts / today 0 new / 48,256 members
DOS学习入门 & 精彩文章 (教学室) » Questions about NET USER
Printable Version  3,376 / 15
Floor1 mayamason Posted 2006-10-09 22:04
初级用户 Posts 19 Credits 46
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.
Floor2 mayamason Posted 2006-10-10 00:02
初级用户 Posts 19 Credits 46
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
Floor3 lxmxn Posted 2006-10-10 02:54
版主 Posts 4,938 Credits 11,386

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.


But this code has certain limitations. If there is also a system account named qgpabc, it will also report that this user exists.
Floor4 weilong888 Posted 2006-10-10 06:20
银牌会员 Posts 548 Credits 1,270
The functions of this for and if are really powerful. You can't understand them thoroughly without trying them several more times.
Floor5 pengfei Posted 2006-10-10 08:37
银牌会员 Posts 485 Credits 1,218 From 湖南.娄底
Two codes to determine if an account exists:



Floor6 lxmxn Posted 2006-10-10 09:22
版主 Posts 4,938 Credits 11,386

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——————
Floor7 mayamason Posted 2006-10-10 19:52
初级用户 Posts 19 Credits 46
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.
Floor8 mayamason Posted 2006-10-10 19:53
初级用户 Posts 19 Credits 46
Brother pengfei, can you explain your first code segment?
Floor9 pengfei Posted 2006-10-10 23:06
银牌会员 Posts 485 Credits 1,218 From 湖南.娄底
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.
Floor10 mayamason Posted 2006-10-11 00:33
初级用户 Posts 19 Credits 46
Pengfei's explanation is too classic.
Floor11 mayamason Posted 2006-10-12 10:02
初级用户 Posts 19 Credits 46
@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.
Floor12 lxmxn Posted 2006-10-14 02:43
版主 Posts 4,938 Credits 11,386
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.``
Floor13 electronixtar Posted 2006-10-14 02:44
铂金会员 Posts 2,672 Credits 7,493
The user name and the full user name are different.
Floor14 vkill Posted 2006-10-14 04:13
金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽
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? “”
Floor15 lxmxn Posted 2006-10-14 12:47
版主 Posts 4,938 Credits 11,386
RE: he200377


  Hehe, thanks for the reminder, forgot that it can also be enclosed in quotes. It seems I haven't done enough testing.
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023