Board index » Visual Studio » HOW TO: Determine if a user is Disabled

HOW TO: Determine if a user is Disabled

Visual Studio325
I wrote a script a few months ago that we ran through our environment to

determine what local users existed on the workstations. If I found any

"non-approved" locally created (non-domain) users in the Administrators or

Power Users groups I disabled them. Now I want to go through and delete

those disabled users. Is there a scripting way to determine if a local user

is disabled?



Thanks,



Tom


-
 

Re:HOW TO: Determine if a user is Disabled

Tom Ker wrote:



Quote
I wrote a script a few months ago that we ran through our environment to

determine what local users existed on the workstations. If I found any

"non-approved" locally created (non-domain) users in the Administrators or

Power Users groups I disabled them. Now I want to go through and delete

those disabled users. Is there a scripting way to determine if a local user

is disabled?



Hi



sUser = "some user"



Set oWshNet = CreateObject("WScript.Network")



Set oUser = GetObject("WinNT://" _

& oWshNet.ComputerName & "/" & sUser & ",user")



bUserDisabled = CBool(oUser.AccountDisabled)



If bUserDisabled Then

WScript.Echo "User is disabled"

Else

WScript.Echo "User is not disabled"

End If





--

torgeir

Microsoft MVP Scripting and WMI, Porsgrunn Norway

Administration scripting examples and an ONLINE version of the 1328 page

Scripting Guide: www.microsoft.com/technet/scriptcenter">www.microsoft.com/technet/scriptcenter





-

Re:HOW TO: Determine if a user is Disabled

Thanks, Torgeir. Works great!





"Torgeir Bakken (MVP)" <Torgeir.Bakken-spam@hydro.com>wrote in message

Quote


sUser = "some user"



Set oWshNet = CreateObject("WScript.Network")



Set oUser = GetObject("WinNT://" _

& oWshNet.ComputerName & "/" & sUser & ",user")



bUserDisabled = CBool(oUser.AccountDisabled)



If bUserDisabled Then

WScript.Echo "User is disabled"

Else

WScript.Echo "User is not disabled"

End If





--

torgeir

Microsoft MVP Scripting and WMI, Porsgrunn Norway

Administration scripting examples and an ONLINE version of the 1328 page

Scripting Guide: www.microsoft.com/technet/scriptcenter">www.microsoft.com/technet/scriptcenter









-