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

  1.  ■<?xml version="1.0" ?>
  2. <package>
  3.     <comment>
  4.         ' *** 
  5.         ' *** ------------------------------------------------------------------------------
  6.         ' *** Filename:        Restrict.wsf
  7.         ' *** ------------------------------------------------------------------------------
  8.         ' *** Description:    Command line interface to the restrictions tool
  9.         ' ***                 This file parses command line parameters an calls functions
  10.         ' ***                 that are defined in clsRestrictions.vbs
  11.         ' *** ------------------------------------------------------------------------------
  12.         ' *** Version:        1.0
  13.         ' *** Notes:        
  14.         ' *** ------------------------------------------------------------------------------
  15.         ' *** Copyright (C) Microsoft Corporation 2005, All Rights Reserved
  16.         ' *** ------------------------------------------------------------------------------
  17.         ' ***
  18.     </comment>
  19.     <job>
  20.         <runtime>
  21.             <description>Restrictions Tool</description>
  22.             <named name="User"        required="false"  many="false"  helpstring="Local User account name to modify." />
  23.             <named name="Create"    required="false"  many="false"  helpstring="Creates an XML file for this user." />
  24.             <named name="Apply"        required="false"  many="false"  helpstring="Applies an XML file for this user." />
  25.             <named name="Accounts"    required="false"  many="false"  helpstring="List user accounts that can be restricted." />
  26.             <named name="XML"        required="false"  many="false"  helpstring="File name of user's XML file." />
  27.             <named name="Lock"        required="false"  many="false"  helpstring="Lock a user's profile." />
  28.             <named name="Unlock"    required="false"  many="false"  helpstring="Unlock a user's profile." />
  29.             <!-- <example>Example: Restrict.wsf /user:TestUser /xml:..\xml\User.Student.xml /apply</example> -->
  30.             <usage>
  31. User Restrictions Tool
  32. Usage: Restrict.wsf [/User:username] [/Create] [/Apply] [/Accounts] [/XML:filename.xml] [/Lock] [/Unlock]
  33. Options :
  34. User    : Local User account name to modify.
  35. Create    : Creates an XML file for this user.
  36. Apply     : Applies an XML file for this user.
  37. Accounts: List user accounts that can be restricted.
  38. XML    : File name of user's XML file.
  39. Lock    : Lock a user's profile.
  40. Unlock    : Unlock a user's profile.
  41. Example : Restrict.wsf /User:TestUser /XML:..\xml\User.Student.xml /Apply
  42. </usage>        
  43.         </runtime>
  44.         
  45.         <resource id="CScriptMessage">Restarting script in command-line mode. Run CmdOn.BAT to set command-line mode as the default mode.</resource>
  46.         <resource id="CScriptTitle">Shared Computer Toolkit: Windows Script Mode Detected</resource>
  47.         <resource id="LockFolderExists">Previously locked profile folder exists. Do you wish to use the same folder for locking this profile?(Y/N)</resource>
  48.         <resource id="FAT32LockProfile">The profile is located on a non NTFS drive. Lock option is not supported for profiles in non NTFS drives.</resource>
  49.         
  50.         <?job error="True" debug="False" ?>
  51.         <script language="VBScript" src="../include/Common.vbs"></script>
  52.         <script language="VBScript" src="../include/libWSF.vbs"></script>
  53.         <script language="VBScript" src="../include/clsLogging.vbs"></script>
  54.         <script language="VBScript" src="../include/clsRestrictions.vbs"></script>
  55.         <script language="VBScript">
  56.         <![CDATA[
  57.             ' ~~~ 
  58.             ' ~~~ Force variables to be declared 
  59.             ' ~~~ 
  60.             Option Explicit
  61.             Call Main("Restrict.hta")
  62.             
  63.             ' ~~~ 
  64.             ' ~~~ Declare variables and constants
  65.             ' ~~~
  66.             Dim oRestriction, oLog, bResult, bOK, sCmdInput
  67.             ' ~~~ ------------------------------------------------------------------------------
  68.             ' ~~~ Logging
  69.             ' ~~~ ------------------------------------------------------------------------------
  70.             ' ~~~ Create logging object
  71.             Set oLog = New Logging
  72.             ' ~~~ Initiate logging
  73.             Call oLog.Open(GetRootFolder & "\log\Restrict.wsf.log")
  74.             Call oLog.Write("Restrict.wsf : Started")
  75.             ' ~~~ Create winrestriction object
  76.             Set oRestriction = New Restriction
  77.             ' ~~~ ------------------------------------------------------------------------------
  78.             ' ~~~ Check script usage
  79.             ' ~~~ ------------------------------------------------------------------------------
  80.             ' ~~~ Simple checks for incorrect usage
  81.             bOK = True
  82.             Select Case WScript.Arguments.Named.Count
  83.                 Case 1
  84.                     If Not(WScript.Arguments.Named.Exists("Accounts")) Then
  85.                         bOK=False
  86.                     End If
  87.                 Case 2
  88.                     If NOT (WScript.Arguments.Named("User") = "") Then
  89.                         IsValidUser(WScript.Arguments.Named("User"))                            
  90.                     End If
  91.             End Select
  92.             ' ~~~ Incorrect usage            
  93.             If Not(bOK) Then
  94.                 Call oLog.Write("Restrict.wsf : Incorrect usage detected")
  95.                  WScript.Arguments.ShowUsage
  96.                  QuitScript()
  97.             End If
  98.             
  99.             ' ~~~ ------------------------------------------------------------------------------
  100.             ' ~~~ Now do restrictions
  101.             ' ~~~ ------------------------------------------------------------------------------
  102.             ' ~~~ Bind to the logging object
  103.             oRestriction.Logging = oLog
  104.             
  105.             ' ~~~ Set the user & source template
  106.             oRestriction.User = WScript.Arguments.Named("User")
  107.             oRestriction.TemplateXML = GetRootFolder & "\xml\" & GetFileName & ".xml"
  108.             Call oLog.Write("Restrict.wsf : XML template set to " & oRestriction.TemplateXML)
  109.             bOK = False
  110.             ' ~~~ Specify the location of the xml file
  111.             If WScript.Arguments.Named.Exists("xml") Then
  112.                 bOK = True
  113.                 oRestriction.UserXML = WScript.Arguments.Named("xml")
  114.                 Call oLog.Write("Restrict.wsf : XML - Filename set to " & oRestriction.UserXML)
  115.             End If
  116.             ' ~~~ Call the Validations subroutine
  117.             Call Validations()
  118.             ' ~~~ Create users XML file
  119.             If WScript.Arguments.Named.Exists("Create") Then
  120.                 bOK = True
  121.                 If oRestriction.CreateXML Then
  122.                     Call oLog.Write("Restrict.wsf : Create - XML file created successfully")
  123.                     WScript.Echo "XML file created successfully"
  124.                 Else
  125.                     Call oLog.Write("Restrict.wsf : Create - Failed to create XML file")
  126.                     WScript.Echo "Failed to create XML file"
  127.                     bOK = False
  128.                 End If
  129.             End If
  130.             ' ~~~ Apply users XML file
  131.             If WScript.Arguments.Named.Exists("Apply") Then
  132.                 IsValidUser(oRestriction.User)                                
  133.                 oRestriction.IsProfileDriveNTFS = oRestriction.IsFileSystemNTFS()
  134.                 bOK = True
  135.                 If oRestriction.ApplyXML Then
  136.                     Call oLog.Write("Restrict.wsf : Apply - XML file applied successfully")
  137.                     WScript.Echo "XML file applied successfully"
  138.                 Else
  139.                     Call oLog.Write("Restrict.wsf : Apply - Failed to apply XML file")
  140.                     WScript.Echo "Failed to apply XML file"
  141.                     bOK = False
  142.                 End If
  143.             End If
  144.             ' ~~~ Lock a users profile
  145.             If WScript.Arguments.Named.Exists("Lock") Then
  146.                 bOK = True
  147.                 If NOT oRestriction.IsFileSystemNTFS Then
  148.                     Wscript.echo getResource("FAT32LockProfile")
  149.                     QuitScript()
  150.                 End If
  151.                 If oRestriction.AccountLocked(oRestriction.User) = False AND oFso.FolderExists(oRestriction.GetProfilePath(oRestriction.User) & ".orig") Then
  152.                     Do 
  153.                         Wscript.stdout.writeline getResource("LockFolderExists")
  154.                         sCmdInput = UCase(Wscript.StdIn.ReadLine) 
  155.                         If sCmdInput = "Y" Then
  156.                             oRestriction.ChangeLockFolder = False
  157.                             Exit Do
  158.                         End If
  159.                         If sCmdInput = "N" Then
  160.                             oRestriction.ChangeLockFolder = True
  161.                             Exit Do
  162.                         End If
  163.                     Loop Until sCmdInput = "Y" OR sCmdInput = "N"
  164.                 End If
  165.                 If oRestriction.LockSharedAccount(oRestriction.User) Then
  166.                     Call oLog.Write("Restrict.wsf : Lock - Profile locked successfully")
  167.                     WScript.Echo "Profile locked successfully"
  168.                 Else
  169.                     Call oLog.Write("Restrict.wsf : Lock - Failed to unlock profile")
  170.                     WScript.Echo "Failed to lock profile"
  171.                     bOK = False
  172.                 End If
  173.             End If
  174.             ' ~~~ Unlock a users profile
  175.             If WScript.Arguments.Named.Exists("Unlock") Then
  176.                 bOK = True
  177.                 If oRestriction.UnlockSharedAccount(oRestriction.User) Then
  178.                     Call oLog.Write("Restrict.wsf : Unlock - Profile locked successfully")
  179.                     WScript.Echo "Profile unlocked successfully"
  180.                 Else
  181.                     Call oLog.Write("Restrict.wsf : Unlock - Failed to unlock profile")
  182.                     WScript.Echo "Failed to unlock profile"
  183.                     bOK = False
  184.                 End If
  185.             End If
  186.             ' ~~~ Display accounts list
  187.             If WScript.Arguments.Named.Exists("Accounts") Then
  188.                 bOK = True
  189.                 WSCript.Echo "Accounts that can have restrictions applied :"
  190.                 WSCript.Echo oRestriction.Accounts(False)
  191.             End If
  192.             If Not(bOK) Then
  193.                 Call oLog.Write("Restrict.wsf : Incorrect usage detected")
  194.                  WScript.Arguments.ShowUsage
  195.                  QuitScript()
  196.             End If
  197.             ' *** 
  198.             ' *** --------------------------------------------------------------------------------
  199.             ' *** Name:            IsValidUser(UserID)
  200.             ' *** --------------------------------------------------------------------------------
  201.             ' *** Purpose:        Checks for the validity of the useraccount
  202.             ' *** --------------------------------------------------------------------------------
  203.             ' *** 
  204.             Sub IsValidUser(UserID)
  205.                 Dim bValid
  206.                 bValid = True
  207.                 If oNetwork.UserName = UserID Then
  208.                     WSCript.Echo "This tool will not modify the currently logged on user."
  209.                     bValid = False
  210.                 ElseIf Right(oRestriction.GetUserSID(UserID),4) = "-500" Then
  211.                     ' ~~~ Administrator account
  212.                     WSCript.Echo "This tool cannot modify the Administrator account."
  213.                     bValid = False
  214.                 ElseIf oRestriction.GetUserSID(UserID) = "" Then
  215.                     WSCript.Echo "This is not a valid user account."
  216.                     bValid = False    
  217.                 ElseIf oRestriction.GetProfilePath(UserID) = "" Then
  218.                     WSCript.Echo " A profile is not created for this user account."
  219.                     bValid = False
  220.                 ElseIf oRestriction.IsUserLoggedOn(UserID) Then
  221.                     WSCript.Echo "The user is currently logged on through fast-user-switching."
  222.                     bValid = False
  223.                 End If
  224.                 If NOT bValid Then
  225.                     WScript.Arguments.ShowUsage
  226.                      QuitScript()
  227.                 End If
  228.             End Sub
  229.             ' *** 
  230.             ' *** --------------------------------------------------------------------------------
  231.             ' *** Name:            Validations()
  232.             ' *** --------------------------------------------------------------------------------
  233.             ' *** Purpose:        Validates the combinations of options in the input arguments
  234.             ' *** --------------------------------------------------------------------------------
  235.             ' *** 
  236.             Sub Validations()
  237.                 If ( WScript.Arguments.Named.Exists("Lock") and WScript.Arguments.Named.Exists("UnLock")) Then
  238.                     Call oLog.Write("Restrict.wsf : Incorrect usage detected")
  239.                      WScript.Arguments.ShowUsage
  240.                      QuitScript()                
  241.                 End If
  242.                 If ( WScript.Arguments.Named.Exists("Create") and WScript.Arguments.Named.Exists("Apply")) Then
  243.                     Call oLog.Write("Restrict.wsf : Incorrect usage detected")
  244.                     WScript.Arguments.ShowUsage
  245.                     QuitScript()                
  246.                 End If
  247.                 
  248.             End Sub
  249.             ' ~~~ ------------------------------------------------------------------------------
  250.             ' ~~~ Tidy up
  251.             ' ~~~ ------------------------------------------------------------------------------
  252.             ' ~~~ Close log
  253.             Call oLog.Close
  254.             ' ~~~ Destroy objects
  255.             Set oRestriction = nothing
  256.             Set oLog = nothing
  257.             UnLoadObjects()
  258.         ]]>
  259.         </script>
  260.     </job>
  261. </package>