Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
When executed as a batch file, why does this not work:
---------------
attrib "c:\Documents and Settings\All Users" +h
attrib "c:\Documents and Settings\svinyard" +h
attrib "C:\Documents and Settings\svinyard.LIBERTY" +h
"dir "c:\Documents and Settings" /B > c:\NTUser.txt"
for /f "delims=," %I IN (c:\NTUser.txt) DO rd /s/q "c:\Documents and Settings\%I"
for /f "delims=," %I IN (c:\NTUser.txt) DO rd /s/q "c:\Documents and Settings\%I"
for /f "delims=," %I IN (c:\NTUser.txt) DO rd /s/q "c:\Documents and Settings\%I"
for /f "delims=," %I IN (c:\NTUser.txt) DO rd /s/q "c:\Documents and Settings\%I"
for /f "delims=," %I IN (c:\NTUser.txt) DO rd /s/q "c:\Documents and Settings\%I"
del /f/q c:\NTUser.txt
attrib "c:\Documents and Settings\All Users" -h
attrib "c:\Documents and Settings\svinyard" -h
attrib "C:\Documents and Settings\svinyard.LIBERTY" -h
---------------The output I get is:
---------------
Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.H:\>\\Sh-nas\install\SCRIPTS\Printer_Scripts\Remove_local_users.bat
H:\>attrib "c:\Documents and Settings\All Users" +h
H:\>attrib "c:\Documents and Settings\svinyard" +h
H:\>attrib "C:\Documents and Settings\svinyard.LIBERTY" +h
File not found - C:\Documents and Settings\svinyard.LIBERTYH:\>"dir "c:\Documents and Settings" /B > c:\NTUser.txt"
The filename, directory name, or volume label syntax is incorrect.
\NTUser.txt) was unexpected at this time.H:\>for /f "delims=," \NTUser.txt) DO rd /s/q "c:\Documents and Settings\I"
H:\>
---------------Yet, if I paste it to a cmd window, all works fine. One more reason for me to learn a new scripting language!

The following line should not be enclosed by "
"dir "c:\Documents and Settings" /B > c:\NTUser.txt"
so replace it with
Dir "c:\Documents and Settings" /B > c:\NTUser.txt
The effect is to miss the C:\NTUser.txt file dooming the balance of code.
I hope you begin your script coding
@Echo Off
otherwise you get each line echoed to the screen with a cumbersome effect.

This is pretty hard to read but if the intent of the first three lines is to hide directories, don't you need ?:
attrib /d /s +h
M2

The attrib to hide the lines is so when DIR /B outputs to txt, it doesn't output hidden drectories, therefore not allowing the script to delete the "all users" folder and my profile. I simply needed to hide the root of that folder, and not the subfolders.
Actually, I have not been running the script with echo off, due to ignorance, but adding it does not seem to correct the issue. This is a very strange problem.
I also removed the quotes, but this had no effect.

Sorry for my previous post, but now I am quite sure to nail the error. It is due to the %I variable in the For statements as that works fine from the command prompt, but the same must be entered as %%I if embedded in a batch script. This explains the For statement failure.

It would seem, sir, that you are the most knowledgeable programmer I have met thus far. Your suggestion corrected the issue and everything works perfectly.
Thank you

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |