?
Solved

Delete local users whose names are in a file.

Posted on 2009-02-16
2
Medium Priority
?
390 Views
Last Modified: 2012-05-06
Hi,

Delete local users whose names are in a file.
I have the machine names in a txt file and the user names also in another file. Check each user is available in each machine and delete the local user account from each machine. Need the success/Failure results too.

Regards
Sharath
0
Comment
Question by:bsharath
2 Comments
 
LVL 47

Assisted Solution

by:Donald Stewart
Donald Stewart earned 400 total points
ID: 23650545
Have you read this How to remove unwanted local user accounts
 
The preferred solution is to delete the local user accounts from each workstation that has them. A possible alternative is to use Group Policy to manipulate the Log On Locally user right to prevent anyone except domain users from logging on to desktop computers targeted by such policy. The Log On Locally user right is found under Computer Configuration \ Windows Settings \ Security Settings \ Local Policies \ User Rights Assignment. But the Log On Locally approach should be carefully tested on a test network before using it on your product network to ensure no unpredictable effects result from implementing it in your environment.
0
 
LVL 14

Accepted Solution

by:
yehudaha earned 1600 total points
ID: 23651243
i did it very quick but i think it will do the job

change name and path in this lines:

Set userlist = fso.OpenTextFile("c:\userlist.txt", 1)
Set complist = fso.OpenTextFile("c:\complist.txt", 1)
Set objlog = fso.CreateTextFile("c:\log.txt", 2)
Set fso = CreateObject("scripting.filesystemobject")
Set objNetwork = CreateObject("Wscript.Network")
Set userlist = fso.OpenTextFile("c:\userlist.txt", 1)
Set complist = fso.OpenTextFile("c:\complist.txt", 1)
Set objlog = fso.CreateTextFile("c:\log.txt", 2)
 
alluserlist = userlist.ReadAll
 
Do Until complist.AtEndOfStream
strComputer = complist.ReadLine
   If Reachable(strComputer) Then
   If per(strComputer) then
Set colAccounts = GetObject("WinNT://" & strComputer & "")
colAccounts.Filter = Array("user")
 
For Each objUser In colAccounts
    If InStr(alluserlist,objUser.Name) Then
    On Error Resume Next
    colAccounts.Delete "user", objUser.Name
    If Err.Number <> 0 Then
    objlog.WriteLine "error deleting " & objUser.Name & " on " & strcomputer & vbcrlf
    On Error Goto 0
    Else
    On Error Goto 0
    objlog.WriteLine "deleting " & objUser.Name & " on " & strcomputer & vbcrlf
    End If
    End If
Next
   Else
     objlog.WriteLine "You Don't Have Permission On " & strComputer & vbCrLf
   End if
Else
objlog.WriteLine strComputer & " Isn't Reachable" & vbCrLf
End if
Loop
 
 
 
Function Reachable(strComputer)
 
 strCmd = "ping -n 1 " & strComputer
 
 Set objShell = CreateObject("WScript.Shell")
 Set objExec = objShell.Exec(strCmd)
 strTemp = UCase(objExec.StdOut.ReadAll)
 
 If InStr(strTemp, "REPLY FROM") Then
 Reachable = True 
 Else
 Reachable = False
 End If
End Function
 
Function per(computer)
        strcomputer = computer
        On Error Resume Next
        Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
        If err.number <> 0 Then
                err.Clear
                per = False
                On Error goto 0
        Else
                per = True
                On Error goto 0
        End If
End Function

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses
Course of the Month13 days, 22 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question