none
Use wildcard in string in vbscript RRS feed

  • Question

  • Hi!

    I have a script written in vbscript that disable local user account. I use this script as GPO. 

    The code disables all users except the users that I indicate in the code. I need the script not to disable users that start with "IUSR". I tried to use the wildcard * like "IUSR*" but didn't work.

    Can anybody help me?

    Set objShell = CreateObject("Wscript.Shell") 
    Set objNetwork = CreateObject("Wscript.Network") 
     
    strComputer = objNetwork.ComputerName 
     
    Set colAccounts = GetObject("WinNT://" & strComputer & "") 
     
    colAccounts.Filter = Array("user") 
        Message = Message & "Local User accounts:" & vbCrLf & vbCrLf 
     
    For Each objUser In colAccounts 
     
        If objUser.Name <> "Administrator" AND objUser.Name <> "Administrador" AND objUser.Name <> "postgres" AND objUser.Name <> "HelpAssistant" AND objUser.Name <> "ASPNET" AND objUser.Name <> "IUSR*" AND objUser.Name <> "IWAM*" AND objUser.Name <> "SUPPORT*" Then 
                Message = Message & objUser.Name 
                If objUser.AccountDisabled = TRUE then 
                     Message = Message & " is currently disabled" & vbCrLf 
                Else 
                    Message = Message & " was enabled" & vbCrLf 
                    objUser.AccountDisabled = True 
                    objUser.SetInfo 
                End if 
        End If 
     
    Next 
     
    ' Initialize title text. 
    Title = "Local User Accounts By Andrew Barnes" 
    objShell.Popup Message, , Title, vbInformation + vbOKOnly


    Tuesday, March 19, 2019 7:35 PM

Answers

All replies