Error in removing users from local admin group
From: Gaurav (gaurav081_at_yahoo.co.in)
Date: 03/25/04
- Next message: P Bull: "Problem passing recordset to dll function"
- Previous message: Torgeir Bakken \(MVP\): "Re: high resolution timer in vbscript"
- Messages sorted by: [ date ] [ thread ]
Date: 25 Mar 2004 04:56:31 -0800
Hi All
Pls help.
I went through the number of scripts you posted for removing the user
from local administrator group.
I have tried all of them but all scripts give me an error
(-2147023519)
when it runs the following lines ..
oGroupAdm.Remove oUser.ADsPath
oGroupAdm.Remove oUser2.ADsPath
its not even deleting a single user from that group(both local and
domain)
' computer name or ip address
Set WshNetwork = WScript.CreateObject("WScript.Network")
sNode = WshNetwork.ComputerName
wscript.echo sNode
' suppress errors
On Error Resume Next
' group name to remove user from
Set oGroupAdm = GetObject("WinNT://" & sNode & "/Administrators")
' loop through all member of the Administrators group
For Each oAdmGrpUser In oGroupAdm.Members
' get the name and make it lowercase
sAdmGrpUser = LCase(oAdmGrpUser.Name)
wscript.echo sAdmGrpUser
' no point in handling Administrator and Domain Admins
' use lowercase letters in the names in the If test!
If (sAdmGrpUser <> "administrator") And _
(sAdmGrpUser <> "domain admins") Then
' try to connect to user object to see if account is a local
user
Set oUser = GetObject("WinNT://" & sNode & "/" _
& oAdmGrpUser.Name & ",user")
If Err.Number = 0 Then
' user is local!
' remove user from Administrators group
oGroupAdm.Remove oUser.ADsPath
'End If
Err.Clear
else
' User is domain - i'm not sure wheather the following part is
correct ??
userdomain = WshNetwork.UserDomain
wscript.echo userdomain
Set oUser2 = GetObject("WinNT://" & userdomain & "/" _
& oAdmGrpUser.Name & ",user")
oGroupAdm.Remove oUser2.ADsPath
End if
End if
Next
- Next message: P Bull: "Problem passing recordset to dll function"
- Previous message: Torgeir Bakken \(MVP\): "Re: high resolution timer in vbscript"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|