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-07-14 23:27
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Solved] How to extract the group the user belongs to? View 1,898 Replies 6
Original Poster Posted 2006-12-24 11:15 ·  中国 陕西 延安 联通
初级用户
Credits 58
Posts 22
Joined 2006-12-07 00:25
19-year member
UID 72763
Gender Male
Status Offline
If the user belongs to the administrator group is displayed as administrators;
If the user belongs to the normal user group is displayed as users;
I wrote a line of code myself, but it can't run. Which big brother can pick out the mistakes,
Or give a new idea is also okay, 3Q!
The code is as follows (this code is wrong!):

for /f "tokens=2 delims=:" in ('net user %username% ^| find "Local Group Members"') do echo %%g


[ Last edited by muya05 on 2006-12-24 at 07:23 PM ]
Floor 2 Posted 2006-12-24 11:24 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
```
@echo off
net user %username%|find /i "*administrators">nul&&echo administrators||echo users
pause
```
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 3 Posted 2006-12-24 11:47 ·  中国 陕西 延安 联通
初级用户
Credits 58
Posts 22
Joined 2006-12-07 00:25
19-year member
UID 72763
Gender Male
Status Offline
RE namejm brother
3Q
It's all my fault for being negligent when asking the question. If there are only two groups, the problem is indeed solved. For multiple groups, the method of the brother also works, but it's a bit troublesome. Looking forward to a better method.
All user groups on my system (WIN 2003 SP1):
__VMWARE__
Administrators
Backup Operators
Distributed COM Users
Guests
HelpServicesGroup
Network Configuration Operators
Performance Log Users
Performance Monitor Users
Power Users
Print Operators
Remote Desktop Users
Replicator
TelnetClients
Users
Floor 4 Posted 2006-12-24 12:18 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
###
Execute in the command line to get the group where the currently logged-in user is located.
for /f "tokens=2" %a in ('net user %username%^|find "本地"') do @echo %~a
Floor 5 Posted 2006-12-24 22:40 ·  中国 陕西 延安 联通
初级用户
Credits 58
Posts 22
Joined 2006-12-07 00:25
19-year member
UID 72763
Gender Male
Status Offline
RE lxmxn brother
3Q!
It would be even better if the " * " (asterisk) could be removed~
Floor 6 Posted 2006-12-24 22:57 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
```for /f "tokens=2 delims=*" %a in ('net user %username%^|find "本地"') do @echo %~a```
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 7 Posted 2006-12-25 08:18 ·  中国 陕西 西安 联通
初级用户
Credits 58
Posts 22
Joined 2006-12-07 00:25
19-year member
UID 72763
Gender Male
Status Offline
The problem is solved.
3Q!
Really want to know how the experts of the DOS Union become accomplished~~?
Salute!

[ Last edited by muya05 on 2006-12-24 at 07:24 PM ]
Forum Jump: