home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2006 May / PCpro_2006_05.ISO / files / free_security / msshared / Shared_Computer_Toolkit_ENU.msi / FileScripts016 < prev    next >
Encoding:
Extensible Markup Language  |  2005-09-02  |  17.2 KB  |  279 lines

  1.  ■<?xml version="1.0" ?>
  2. <package>
  3.     <comment>
  4.         ' ***
  5.         ' *** ------------------------------------------------------------------------------
  6.         ' *** Filename:        Accounts.wsf
  7.         ' *** ------------------------------------------------------------------------------
  8.         ' *** Description:    Allows for quick enabling/disabling of accounts
  9.         ' *** ------------------------------------------------------------------------------
  10.         ' *** Version:        1.0
  11.         ' *** Notes:        
  12.         ' *** ------------------------------------------------------------------------------
  13.         ' *** Copyright (C) Microsoft Corporation 2005, All Rights Reserved
  14.         ' *** ------------------------------------------------------------------------------
  15.         ' ***
  16.     </comment>
  17.     <job>
  18.         <runtime>
  19.             <description>Allows for quick enabling/disabling of accounts</description>
  20.             <named name="Enable" required="false" many="false" helpstring="Enables a local account" />
  21.             <named name="Disable" required="false" many="false" helpstring="Disables a local account" />
  22.             <named name="List" required="false" many="false" helpstring="Lists local accounts and their status" />
  23.             <!--<example>Example: Accounts.wsf /Disable:username</example>-->
  24.             <usage>
  25. Accounts Tool
  26. Usage: Accounts.wsf [/Enable:username] [/Disable:username] [/List]
  27. Options :
  28. Enable    : Enables a local account.
  29. Disable    : Disables a local account.
  30. List     : Lists local accounts and their status.
  31. Example : Accounts.wsf /Disable:username
  32. </usage>
  33.         </runtime>
  34.         <resource id="CScriptMessage">Restarting script in command-line mode. Run CmdOn.BAT to set command-line mode as the default mode.</resource>
  35.         <resource id="CScriptTitle">Shared Computer Toolkit: Windows Script Mode Detected</resource>
  36.         <?job error="True" debug="False" ?>
  37.         <script language="VBScript" src="../include/Common.vbs"></script>
  38.         <script language="VBScript" src="../include/libWSF.vbs"></script>
  39.         <script language="VBScript" src="../include/clsLogging.vbs"></script>
  40.         <script language="VBScript">
  41.         <![CDATA[
  42.             ' ~~~ 
  43.             ' ~~~ Force variables to be declared 
  44.             ' ~~~ 
  45.             Option Explicit
  46.             ' ~~~ Call the Main Sub 
  47.             Call Main("")
  48.             ' ~~~ 
  49.             ' ~~~ Declare variables and constants
  50.             ' ~~~ 
  51.             Dim sAppDir, bOK
  52.             Dim colItems, oItem, sInstaller, oUser, sUser
  53.         
  54.             sAppDir   = RegRead(TOOLKITKEY & "TargetDir")
  55.             sInstaller = RegRead(TOOLKITKEY & "SCTInstaller")
  56.             ' ~~~ ------------------------------------------------------------------------------
  57.             ' ~~~ Check script usage
  58.             ' ~~~ ------------------------------------------------------------------------------
  59.             
  60.             ' ~~~ Assume usage is ok
  61.             bOK = True        
  62.             ' ~~~ Simple checks for incorrect usage
  63.             Select Case WScript.Arguments.Named.Count
  64.                 Case 0
  65.                     ' ~~~ Cannot call without parameters
  66.                     bOK = False
  67.             End Select
  68.             If Not(WScript.Arguments.Named.Exists("Enable")) and Not(WScript.Arguments.Named.Exists("Disable")) and Not(WScript.Arguments.Named.Exists("List")) Then
  69.                 bOK = False
  70.             End If
  71.             ' ~~~ If incorrect usage display message and quit
  72.             If Not(bOK) Then
  73.                  WScript.Arguments.ShowUsage
  74.                  QuitScript()
  75.             End If
  76.             ' ~~~ List Accounts
  77.             If WScript.Arguments.Named.Exists("List") Then
  78.                 Call ListAccounts
  79.             End If
  80.             ' ~~~ Enable Account
  81.             If WScript.Arguments.Named.Exists("Enable") Then
  82.                 sUser = WScript.Arguments.Named("Enable")
  83.                 Call EnableUser
  84.             End If
  85.             ' ~~~ Disable Account
  86.             If WScript.Arguments.Named.Exists("Disable") Then
  87.                 sUser = WScript.Arguments.Named("Disable")
  88.                 Call DisableUser
  89.             End If
  90.             ' ~~~ Destroy objects
  91.             UnLoadObjects()
  92.             ' ***
  93.             ' *** ------------------------------------------------------------------------------
  94.             ' *** Name:        IsInvalidAccount
  95.             ' *** ------------------------------------------------------------------------------
  96.             ' *** Purpose:        Determines which accounts can be modified or listed
  97.             ' *** ------------------------------------------------------------------------------
  98.             ' ***
  99.             Function IsInvalidAccount
  100.             Dim oAccount
  101.             
  102.             IsInValidAccount = False
  103.             Select Case UCase(oItem.Name)
  104.                 Case "HELPASSISTANT"
  105.                     IsInValidAccount = True
  106.                 Case "ASPNET"
  107.                     IsInValidAccount = True
  108.                 Case "SUPPORT_388945A0"
  109.                     IsInValidAccount = True
  110.                 Case "SQLDEBUGGER"
  111.                     IsInValidAccount = True
  112.                 Case "ACTUSER"
  113.                     IsInValidAccount = True
  114.                 Case "IUSR_" & UCase(oNetwork.ComputerName)
  115.                     IsInValidAccount = True
  116.                 Case "IWAM_" & UCase(oNetwork.ComputerName)
  117.                     IsInValidAccount = True
  118.                 Case "VUSR_" & UCase(oNetwork.ComputerName)
  119.                     IsInValidAccount = True
  120.                 Case UCase(oNetwork.UserName)
  121.                     IsInValidAccount = True
  122.                 Case oNetwork.UserName
  123.                     IsInValidAccount = True
  124.                 Case sInstaller
  125.                     IsInValidAccount = True
  126.             End Select
  127.             
  128.                 Set oAccount = oWMIService.Get("Win32_UserAccount.Name='" & oItem.Name & "',Domain='" & oNetwork.ComputerName & "'")
  129.                 
  130.                 If Right( oAccount.SID , 4 ) = "-500" Then
  131.                     ' ~~~ Administrator account
  132.                     IsInValidAccount = True
  133.                 ElseIf Right( oAccount.SID , 4 ) = "-501" Then
  134.                     ' ~~~ Guest account
  135.                     IsInValidAccount = True
  136.                 End If
  137.                 Set oAccount = nothing
  138.                 
  139.             End Function
  140.             ' ***
  141.             ' *** ------------------------------------------------------------------------------
  142.             ' *** Name:        EnableUser
  143.             ' *** ------------------------------------------------------------------------------
  144.             ' *** Purpose:        Enables the specified account... 
  145.             ' ***            account can login and, and will appear on Windows Welcome
  146.             ' *** ------------------------------------------------------------------------------
  147.             ' ***
  148.             Sub EnableUser
  149.             
  150.             Set colItems = oWMIService.ExecQuery _
  151.                 ("Select * from Win32_UserAccount Where LocalAccount = True")
  152.  
  153.             For Each oItem in colItems 
  154.                 If Not(IsInvalidAccount()) and LCase(oItem.Name) = LCase(sUser) then
  155.                     Set oUser = GetObject("WinNT://./" & oItem.Name)
  156.                     oUser.AccountDisabled = False
  157.                     oUser.setinfo
  158.                     Wscript.Echo
  159.                     Wscript.Echo "Account: " & sUser & " is now enabled."
  160.                     Wscript.Echo
  161.                     Exit Sub
  162.                 End If
  163.             Next
  164.                 Set colItems = nothing
  165.                 Set oItem = nothing
  166.                 Set oUser = nothing
  167.                 Wscript.Echo
  168.                 Wscript.Echo "Account: " & sUser & " does not exist or cannot be enabled using this tool."
  169.                 Wscript.Echo
  170.             End Sub
  171.             ' ***    
  172.             ' *** ------------------------------------------------------------------------------
  173.             ' *** Name:        DisableUser
  174.             ' *** ------------------------------------------------------------------------------
  175.             ' *** Purpose:        Disables the specified account...
  176.             ' ***            account cannot login and, and will not appear on Windows Welcome
  177.             ' *** ------------------------------------------------------------------------------
  178.             ' ***
  179.             Sub Disableuser
  180.             
  181.             Set colItems = oWMIService.ExecQuery _
  182.                 ("Select * from Win32_UserAccount Where LocalAccount = True")
  183.               
  184.             For Each oItem in colItems 
  185.                 If Not(IsInvalidAccount()) and LCase(oItem.Name) = LCase(sUser) then
  186.                     Set oUser = GetObject("WinNT://./" & oItem.Name)
  187.                     oUser.AccountDisabled = True
  188.                     oUser.setinfo
  189.                     Wscript.Echo
  190.                     Wscript.Echo "Account: " & sUser & " is now disabled."
  191.                     Wscript.Echo
  192.                     Exit Sub
  193.                 End If
  194.             Next
  195.     
  196.                 Set colItems = nothing
  197.                 Set oItem = nothing
  198.                 Set oUser = nothing
  199.                 Wscript.Echo
  200.                 Wscript.Echo "Account: " & sUser & " does not exist or cannot be disabled using this tool."
  201.                 Wscript.Echo
  202.             End Sub
  203.             ' ***
  204.             ' *** ------------------------------------------------------------------------------
  205.             ' *** Name:        ListAccounts
  206.             ' *** ------------------------------------------------------------------------------
  207.             ' *** Purpose:        List local accounts and their status: Enabled/Disabled 
  208.             ' *** ------------------------------------------------------------------------------
  209.             ' ***
  210.             Sub ListAccounts
  211.             Dim sStatus
  212.             
  213.             Set colItems = oWMIService.ExecQuery _
  214.                 ("Select * from Win32_UserAccount Where LocalAccount = True")
  215.             Wscript.Echo    
  216.             Wscript.Echo "Local accounts and their status:"
  217.             Wscript.Echo 
  218.  
  219.             For Each oItem in colItems
  220.             
  221.             If Not(IsInvalidAccount()) then
  222.                 Set oUser = GetObject("WinNT://./" & oItem.Name) 
  223.                 If oUser.AccountDisabled then 
  224.                     sStatus = "Disabled"
  225.                 Else
  226.                     sStatus = "Enabled"
  227.                 End If            
  228.                 
  229.                 Wscript.Echo    
  230.                 Wscript.Echo "Account: " & oItem.Name
  231.                 Wscript.Echo "Status : " & sStatus
  232.                 
  233.             End If
  234.         
  235.             Next
  236.             
  237.             Set colItems = nothing
  238.             Set oItem = nothing
  239.             Set oUser = nothing
  240.             Wscript.Echo
  241.             QuitScript()
  242.             End Sub
  243.         ]]>
  244.         </script>
  245.     </job>
  246. </package>