中国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-06 22:29
48,039 topics / 350,124 posts / today 0 new / 48,252 members
DOS批处理 & 脚本技术(批处理室) » Need a script to delete extra system accounts
Printable Version  1,835 / 18
Floor1 dato Posted 2007-12-15 21:56
高级用户 Posts 377 Credits 916
Floor2 lxmxn Posted 2007-12-15 23:06
版主 Posts 4,938 Credits 11,386
Try this?
Floor3 dato Posted 2007-12-15 23:37
高级用户 Posts 377 Credits 916
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.
Floor4 lxmxn Posted 2007-12-15 23:42
版主 Posts 4,938 Credits 11,386
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 ]
Floor5 dato Posted 2007-12-15 23:59
高级用户 Posts 377 Credits 916
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,
Floor6 dato Posted 2007-12-17 18:57
高级用户 Posts 377 Credits 916
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.
Floor7 huahua0919 Posted 2007-12-17 20:31
银牌会员 Posts 780 Credits 1,608
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.
Floor8 dato Posted 2007-12-17 20:55
高级用户 Posts 377 Credits 916
【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.
Floor9 lxmxn Posted 2007-12-17 21:05
版主 Posts 4,938 Credits 11,386
Try this again:

[ Last edited by lxmxn on 2007-12-17 at 09:06 PM ]
Floor10 dato Posted 2007-12-17 21:19
高级用户 Posts 377 Credits 916
Floor11 everest79 Posted 2007-12-17 21:42
金牌会员 Posts 1,127 Credits 2,564
Floor12 dato Posted 2007-12-17 21:44
高级用户 Posts 377 Credits 916
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.
Floor13 everest79 Posted 2007-12-17 21:53
金牌会员 Posts 1,127 Credits 2,564
Doesn't my method work?
Floor14 dato Posted 2007-12-17 22:00
高级用户 Posts 377 Credits 916
Floor15 everest79 Posted 2007-12-17 22:09
金牌会员 Posts 1,127 Credits 2,564
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.
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023