Jump to content

Recommended Posts

Posted

hi,

Has anyone got a script that deletes all local user accounts, except ones I specify such as the administrator account and service accounts and also enables and sets a password for the local admin account.

Its for windows7.

 

Thanks

Posted

I have this batch file:

 

@echo off
c:
cd\
cd "c:\Documents and Settings\"
dir *.* /b /o:d > \dirs.txt
for /f "tokens=*" %%a in (\dirs.txt) do call :DelFiles "%%a"
del \dirs.txt
exit /b

:DelFiles %1
set Flag=0
if %1=="All Users" set Flag=1
if %1=="Administrator" set Flag=1
if "%Flag%"=="0" (
cd %1
attrib *.* -r /s
cd..
rem change rd %1 /s /q
rem for no confirmation
rd %1 /s /q
)

 

or a nice VB script:

 

On Error Resume Next
 Dim obtainfolder
 Dim Pathfinder
 Dim strPath

 Set fso = CreateObject("Scripting.FileSystemObject")

 strPath = "C:\Documents and Settings\"
 
 userexcludelist = "Administrator,All Users,Default User,localservice,networkservice,"

 Set f = fso.GetFolder(strPath)

 ' Loop through all subfolders
 For Each fldrItem in f.SubFolders
   fldrName = fldrItem.name
   If Right(strPath,1) <> "\" Then
     Pathfinder = strPath & "\" & fldrName
   Else
     Pathfinder = strPath & fldrName
   End If

   If InStr(1, ".00", fldrName, 1) Then
     set obtainfolder = fso.GetFolder(Pathfinder)
     obtainfolder.Delete true
   Else
               
               End If
 Next

 ' Clean up objects
 Set fso = Nothing
 Set fc = Nothing

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...