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-07 00:41
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Need a script to delete extra system accounts View 1,844 Replies 18
Original Poster Posted 2007-12-15 21:56 ·  中国 上海 杨浦区 电信
高级用户
★★★
Credits 916
Posts 377
Joined 2004-03-08 00:00
22-year member
UID 19523
Gender Male
Status Offline
Floor 2 Posted 2007-12-15 23:06 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
Try this?
for /f "delims=, tokens=2 skip=2" %a in ('wmic useraccount get name /format:CSV') do @call echo net user "%a" /del
Floor 3 Posted 2007-12-15 23:37 ·  中国 上海 杨浦区 电信
高级用户
★★★
Credits 916
Posts 377
Joined 2004-03-08 00:00
22-year member
UID 19523
Gender Male
Status Offline
Yeah, still no good.

The structure the moderator gave can conveniently get the username, but when I integrated it, it became

setlocal enabledelayedexpansion
for /f "eol=; tokens=* delims=" %%i in (Process.ini) do set %%i=A
for /f "delims=, tokens=2 skip=2" %%i in ('wmic useraccount get name /format:CSV') do if /I not defined %%i echo %%i
pause
----------------------------
D:\del>setlocal enabledelayedexpansion

D:\del>for /F "eol=; tokens=* delims=" %i in (Process.ini) do set %i=A

D:\del>set fdiy=A

D:\del>set guest=A

D:\del>for /F "delims=, tokens=2 skip=2" %i in ('wmic useraccount get name /form
at:CSV') do if /I not defined %i echo %i

echo 1 1 1I not defined 1 1 1
1 1 1

echo fdiy/I not defined fdiy
fdiy

echo GuestI not defined Guest
Guest

D:\del>pause
Press any key to continue. . .

I don't know where that I after the username is coming from.
Floor 4 Posted 2007-12-15 23:42 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
if /I not defined %%i echo %%i

The "/I" parameter of the if command is used to ignore case when comparing strings; it can't be used the way you did.

Also, I added a call in front of my command, maybe try that first?

I haven't specifically tested it yet.

[ Last edited by lxmxn on 2007-12-15 at 11:43 PM ]
Floor 5 Posted 2007-12-15 23:59 ·  中国 上海 杨浦区 电信
高级用户
★★★
Credits 916
Posts 377
Joined 2004-03-08 00:00
22-year member
UID 19523
Gender Male
Status Offline
Yeah, thanks lxman, good night. I'll come back and study it again tomorrow.
I tried your code and there wasn't a single problem, weird,
Floor 6 Posted 2007-12-17 18:57 ·  中国 上海 杨浦区 电信
高级用户
★★★
Credits 916
Posts 377
Joined 2004-03-08 00:00
22-year member
UID 19523
Gender Male
Status Offline
After messing with it for half a day it's still not working. Actually I don't really understand this kind of matching with the for /I parameter either, but this bit of code was written by a friend on the forum. In the end I only discovered that wmic's output turned out to be unicode-encoded stuff. I don't know what problem if is having either. Moderator, is there any way to format the output of net user?

wmic useraccount get name /format:CSV>b.txt
setlocal enabledelayedexpansion
for /f "eol=; tokens=* delims=" %%i in (a.txt) do set %%i=A
for /f "delims=, tokens=2 skip=2" %%i in (b.txt) do if /I not defined %%i echo %%i
Once it gets to the line above, all information is gone.
Floor 7 Posted 2007-12-17 20:31 ·  中国 江苏 苏州 移动
银牌会员
★★★
Credits 1,608
Posts 780
Joined 2007-10-07 10:19
18-year member
UID 99089
Gender Male
Status Offline
for /f "eol=; tokens=* delims=" %%i in (a.txt) do set %%i=A
I really don't understand how the OP wrote this. According to the above way of writing it, every line in text file a.txt gets replaced with A.
Floor 8 Posted 2007-12-17 20:55 ·  中国 上海 杨浦区 电信
高级用户
★★★
Credits 916
Posts 377
Joined 2004-03-08 00:00
22-year member
UID 19523
Gender Male
Status Offline
【Discussion】Use TASKKILL to close all processes (except specified ones)
http://www.cn-dos.net/forum/viewthread.php?tid=27155&fpage=1&highlight=%E8%BF%9B%E7%A8%8B

This is the prototype of it. Personally I feel that set is only there to satisfy the for syntax requirement and has no real meaning; the if defind below is the key. But the strange thing is that once the output comes through wmic, it changes.
Floor 9 Posted 2007-12-17 21:05 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
Try this again:
for /f "tokens=*" %a in ('wmic useraccount get name^|more +1') do @call net user %a


[ Last edited by lxmxn on 2007-12-17 at 09:06 PM ]
Floor 10 Posted 2007-12-17 21:19 ·  中国 上海 杨浦区 电信
高级用户
★★★
Credits 916
Posts 377
Joined 2004-03-08 00:00
22-year member
UID 19523
Gender Male
Status Offline
Floor 11 Posted 2007-12-17 21:42 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
Floor 12 Posted 2007-12-17 21:44 ·  中国 上海 杨浦区 电信
高级用户
★★★
Credits 916
Posts 377
Joined 2004-03-08 00:00
22-year member
UID 19523
Gender Male
Status Offline
Mainly, recently the computer lab needs to call shutdown. Personally I think shutdown -l logoff gives stronger controllability. If there's a problem, the scheduled task can still be canceled some other way while the machine is powered on. But after trying many kinds of software with logoff capability, when executing a scheduled task it has to correspond to the logged-in account before it can run, so we have to automate deleting any accounts created by students themselves. There may be at least 3 reserved accounts. I had also tried this code earlier, and I don't know why this time when taking values from wmic it has that /I after it; I also don't know where that popped out from. I tried outputs like net user and they were all ANSI encoded. I don't know why such a strange problem is appearing. My system is win2003 se sp2.
Floor 13 Posted 2007-12-17 21:53 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
Doesn't my method work?
Floor 14 Posted 2007-12-17 22:00 ·  中国 上海 杨浦区 电信
高级用户
★★★
Credits 916
Posts 377
Joined 2004-03-08 00:00
22-year member
UID 19523
Gender Male
Status Offline
Floor 15 Posted 2007-12-17 22:09 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
The account you're getting a deletion error on should be full-width characters, hehe.
If you want to normalize the net user list, you can try enumerating the workgroups under net localgroup.
Forum Jump: