DougInCanada
Technical User
I was able to setup a script to remove local users from the local Admin group on a given computer. My problem now is that some DOMAIN users have been added to the local Admin group on some computers.
My code is as follows:
When the script runs, it needs to enumerate the members (users) of the local Admin group, but differenciate between DOMAIN/username and username (the local user account). The same username could be set up both locally and assigned to the Admins group, as well as the domain username simply assigned to the local Admin group. Both usernames would appear in the Local Administrators group with the domain username appearing as DOMAIN/username. When I wscript.echo the members, the username appears twice, but only removes the local username, not the DOMAIN username. Or is there any way to match the Domain and the username when checking each member (ie: " mem.name = "DOMAINX" & UName)?
Is there a way to determine if the current user is logged on locally or to a domain?
Any help on this would be greatly appreciated.
Doug
My code is as follows:
Code:
dim UName, CName, Sh, Env, Net, fso, textfile
on error resume next
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
set textfile = fso.CreateTextFile ("C:\update\update.log",2,true)
Set Sh = WScript.CreateObject("Wscript.Shell")
Set Env = Sh.Environment("SYSTEM")
If Env("USERNAME")="" then
Set Net=WScript.CreateObject("Wscript.Network")
UName = Net.UserName
CName = Net.ComputerName
Else
UName = Env("USERNAME")
CName = Env("COMPUTER")
End If
strComputer = "."
Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")
For Each mem In objGroup.Members
if mem.name = uname then
textfile.WriteLine mem.name & " is a member of the " & objgroup.name & " group." & vbcrlf
Set objUser = GetObject("WinNT://" & CName & "/" & UName & ",user")
objGroup.Remove(objUser.ADsPath)
objGroup.SetInfo
end if
Next
textfile.WriteBlankLines(1)
Set objUser = GetObject("WinNT://" & strComputer & "/Administrator,user")
objUser.SetPassword "<New Password Here>"
objUser.SetInfo
textfile.WriteLine "Password reset was successful." & vbcrlf
textfile.close
set textfile = nothing
set Sh = nothing
Is there a way to determine if the current user is logged on locally or to a domain?
Any help on this would be greatly appreciated.
Doug