none
Contas de Usuários Locais (XP e Vista) RRS feed

  • Pergunta

  • Bom Dia a todos

        Preciso de um script que Desative todas as contas Locais com excessão do Administrator, renomei essa conta e altere a senha.
        Renomear a conta e alterar a senha eu ja consegui, mas não consegui desativar todas as contas com excessão do Admin.


    Agradeço a ajuda.

    vlw!

    Segue o codigo que estou usando:

    Set oWshNet = CreateObject("WScript.Network")
    	sComputerName = oWshNet.ComputerName
    
    	'[] Usuário e Senha
    	sNewUser = "xxx"
    	sNewPassword = "*xxx"
    	
    	usuario = UCase(sNewUser)
    	sOldUser = GetAdministratorName(sComputerName)
    
    On Error Resume Next
    	Set oUser = GetObject("WinNT://" & sComputerName & "/" _
    	& sOldUser & ",user")
    
    If LCase(sNewUser) <> LCase(sOldUser) Then
    	Set oComputer = GetObject("WinNT://" & sComputerName)
    	Set oNewUser = oComputer.MoveHere(oUser.ADsPath, sNewUser)
    	'wscript.echo "setado: " & sNewUser
    End If
    On Error Goto 0
    
    On Error Resume Next 
    	Set oUser = GetObject("WinNT://" & sComputer & "/" & sAdminName & ",user") 
    	oUser.SetPassword sNewPassword 
    	oUser.SetInfo 
    	'wscript.echo "setado: " & sNewPassword
    On Error Goto 0 
    
    Function GetAdministratorName(sComputerName)
    	Dim sUserSID, oWshNetwork, oUserAccount
    	Set oUserAccounts = GetObject( _
    	"winmgmts:{impersonationLevel=impersonate}!//" _
    	& sComputerName & "/root/cimv2").ExecQuery( _
    	"Select Name, SID from Win32_UserAccount WHERE Domain = '" _
    	& sComputerName & "'")
    	On Error Resume Next
    		For Each oUserAccount In oUserAccounts
    			If Left(oUserAccount.SID, 9) = "S-1-5-21-" And _
    				Right(oUserAccount.SID, 4) = "-500" Then
    				GetAdministratorName = oUserAccount.Name
    		Exit For
    		End if
    		Next
    End Function





    Douglas Oliveira Admin Rede []
    quarta-feira, 22 de julho de 2009 12:06

Respostas

  • Peguei o seu script e adicionei uma Sub chamada DisableAllEcpt. Conforme coloquei abaixo vc passa como parametro a conta sNewUser que ele ira desabilitar todas as outras contas locais com exceçao desta (Admin renomeado).


    Set oWshNet = CreateObject("WScript.Network")
     sComputerName = oWshNet.ComputerName

     '[] Usuário e Senha
     sNewUser = "xxx"
     sNewPassword = "*xxx"
     
     usuario = UCase(sNewUser)
     sOldUser = GetAdministratorName(sComputerName)

    On Error Resume Next
     Set oUser = GetObject("WinNT://" & sComputerName & "/" _
     & sOldUser & ",user")

    If LCase(sNewUser) <> LCase(sOldUser) Then
     Set oComputer = GetObject("WinNT://" & sComputerName)
     Set oNewUser = oComputer.MoveHere(oUser.ADsPath, sNewUser)
     'wscript.echo "setado: " & sNewUser
    End If
    On Error Goto 0

    On Error Resume Next
     Set oUser = GetObject("WinNT://" & sComputer & "/" & sNewUser & ",user")
     oUser.SetPassword sNewPassword
     oUser.SetInfo
     'wscript.echo "setado: " & sNewPassword
    On Error Goto 0

    DisableAllEcpt SNewUser

    Sub DisableAllEcpt(user)

    Set objNetwork = CreateObject("Wscript.Network")
    strComputer = objNetwork.ComputerName

    Set colAccounts = GetObject("WinNT://" & strComputer & "")
    colAccounts.Filter = Array("user")

    For Each objUser In colAccounts
        If objUser.Name <> user Then
         Set objUser = GetObject("WinNT://" & strComputer & "/" & objUser.Name)
      objUser.AccountDisabled = True
      objUser.SetInfo
        End If
    Next

    End Sub


    Function GetAdministratorName(sComputerName)
     Dim sUserSID, oWshNetwork, oUserAccount
     Set oUserAccounts = GetObject( _
     "winmgmts:{impersonationLevel=impersonate}!//" _
     & sComputerName & "/root/cimv2").ExecQuery( _
     "Select Name, SID from Win32_UserAccount WHERE Domain = '" _
     & sComputerName & "'")
     On Error Resume Next
      For Each oUserAccount In oUserAccounts
       If Left(oUserAccount.SID, 9) = "S-1-5-21-" And _
        Right(oUserAccount.SID, 4) = "-500" Then
        GetAdministratorName = oUserAccount.Name
      Exit For
      End if
      Next
    End Function


    Ate mais
    Angelo

    sexta-feira, 14 de agosto de 2009 06:49