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

  1.  ■<?xml version="1.0" ?>
  2. <package>
  3.     <comment>
  4.         ' *** 
  5.         ' *** ----------------------------------------------------------------------------
  6.         ' *** Filename:        ProfileMgr.wsf
  7.         ' *** ------------------------------------------------------------------------------
  8.         ' *** Description:    Command line interface to the Profile Manager tool
  9.         ' ***                 This file parses command line parameters and calls functions
  10.         ' ***                 that are defined in clsProfileMgr.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>Create User Profiles Tool</description>
  22.             <named name="create" required="false" type="simple" helpstring="Creates a user profile" />
  23.             <unnamed name="delete" required="true" many="false" helpstring="Deletes a user profile" />
  24.             <unnamed name="list" required="false" many="false" helpstring="Lists the user accounts and profile paths that can be updated using this tool." />
  25.             <named name="domain" required="false" many="false" helpstring="" />
  26.             <named name="drive" required="false" many="false" helpstring="" />
  27.             <usage>Profile Manager tool
  28. Usage: ProfileMgr [/Create] [/Delete] [/List] [/Domain:domain] [/Drive:drive]
  29.                   account password
  30. Options:
  31.   /Create - Create a new user profile for an account.
  32.   /Delete - Delete an existing user profile (password not required).
  33.   /List   - List the accounts and profiles that can be managed.
  34.   /Domain - Create a user profile for a domain account.
  35.   /Drive  - Create the user profile on an alternate drive.
  36. Examples:
  37.   ProfileMgr.wsf /Create jimsmith Password! /Domain:Galaxy /Drive:D
  38.   ProfileMgr.wsf /Create Public pass
  39.   ProfileMgr.wsf /Delete Public 
  40.   ProfileMgr.wsf /List</usage>
  41.         </runtime>
  42.         
  43.         <resource id="IncorrectUsage">Incorrect Usage detected</resource> 
  44.         <resource id="CreateSuccess">Profile has been successfully created</resource>
  45.         <resource id="CreateFailure">Profile creation has failed. Ensure a valid password has been entered.</resource>
  46.         <resource id="DeleteSuccess">Profile has been successfully deleted</resource>
  47.         <resource id="DeleteFailure">Profile deletion has failed.</resource>
  48.         <resource id="EmptyUser">Please enter the user name</resource>
  49.         <resource id="LoggedOnUser">The user is currently logged on</resource>
  50.         <resource id="SwitchUser">The user is logged on through fast-user-switching</resource>
  51.         <resource id="InvalidUser">Please enter a valid user</resource>
  52.         <resource id="InvalidDrive">Please enter a valid drive</resource>
  53.         <resource id="InvalidDomain">Please enter the correct domain for the user</resource>
  54.         <resource id="CannotDelete">Profile cannot be deleted</resource>
  55.         <resource id="NoProfile">Profile does not exist for the user</resource>
  56.         <resource id="DomainError">Either the user name or the domain is invalid</resource>
  57.         <resource id="ProfileExists">Profile already exists for the user</resource>
  58.         <resource id="CScriptMessage">Restarting script in command-line mode. Run CmdOn.BAT to set command-line mode as the default mode.</resource>
  59.         <resource id="CScriptTitle">Shared Computer Toolkit: Windows Script Mode Detected</resource>
  60.         
  61.         <?job error="True" debug="False" ?>
  62.         <script language="VBScript" src="../include/Common.vbs"></script>
  63.         <script language="VBScript" src="../include/libWSF.vbs"></script>
  64.         <script language="VBScript" src="../include/clsProfileMgr.vbs"></script>
  65.         <script language="VBScript" src="../include/clsLogging.vbs"></script>
  66.         <script language="VBScript">
  67.         <![CDATA[
  68.             ' ~~~ 
  69.             ' ~~~ Force variables to be declared 
  70.             ' ~~~ 
  71.             Option Explicit
  72.             ' ~~~ Call the Main sub
  73.             Call Main("ProfileMgr.hta")        
  74.             ' ~~~ 
  75.             ' ~~~ Declare variables and constants
  76.             ' ~~~ 
  77.             Dim oProfileMgr, oLog
  78.             Dim args, strArgs, delArgs, CreateArgs, DeleteArgs
  79.             Dim StdOut,StdIn, sUser, sPassword, sDomain, sDrive, bOk 
  80.             ' ~~~ ------------------------------------------------------------------------------
  81.             ' ~~~ Logging
  82.             ' ~~~ ------------------------------------------------------------------------------
  83.             ' ~~~ Create logging object
  84.             Set oLog = New Logging    
  85.             Set StdOut = Wscript.stdout
  86.             Set StdIn  =  Wscript.stdin
  87.             ' ~~~ Initiate logging
  88.             Call oLog.Open(GetRootFolder & "\log\ProfileMgr.wsf.log")
  89.             Call oLog.Write("ProfileMgr.wsf : Started")
  90.             
  91.             bOk = False
  92.             sUser = ""
  93.             sPassword = ""
  94.             sDomain = ""
  95.             sDrive = ""
  96.             
  97.             Set args = WScript.Arguments
  98.             ' ~~~ Create the ProfileMgr object
  99.             Set oProfileMgr = New ProfileMgr
  100.             
  101.             ' ~~~ Bind to the logging object
  102.             oProfileMgr.Logging = oLog
  103.             ' ~~~ --------------------------------------------------------------------------------
  104.             ' ~~~ Perform list profiles
  105.             ' ~~~ --------------------------------------------------------------------------------
  106.             If WScript.Arguments.Named.Exists("list") Then
  107.                 bOK = True
  108.                 Call oLog.Write("ProfileMgr.wsf : list")
  109.                 oProfileMgr.ShowUserAndProfile()
  110.             End If
  111.             ' ~~~ --------------------------------------------------------------------------------
  112.             ' ~~~ Perform create profile
  113.             ' ~~~ --------------------------------------------------------------------------------
  114.             If WScript.Arguments.Named.Exists("create") Then
  115.                 Call oLog.Write("ProfileMgr.wsf : create")
  116.                 bOK = True
  117.                 If args.count < 1 or args.count > 5 Then
  118.                     Call oLog.Write("ProfileMgr.wsf : " & getResource("IncorrectUsage") )
  119.                     ProfileMgrQuitScript()    
  120.                 End If
  121.                 ' ~~~ To check how the user wants to give the inputs
  122.                 If args.count = 1 Then
  123.                     StdOut.write "Username:"
  124.                     sUser = StdIn.ReadLine
  125.                     StdOut.write "Password:"
  126.                     sPassword = StdIn.ReadLine
  127.                     StdOut.write "Domain:"
  128.                     sDomain = StdIn.ReadLine
  129.                     StdOut.write "Drive:"
  130.                     sDrive = StdIn.ReadLine
  131.                     
  132.                     CreateArgs = Array(sUser,sPassword,sDomain,sDrive)
  133.                     
  134.                     ' ~~~ Call the function in the class to check the arguments
  135.                     strArgs = oProfileMgr.CheckArguments(CreateArgs)
  136.                 Else 
  137.                     ' ~~~ Parse the command line and get the inputs
  138.                     strArgs = GetCreateInputs()
  139.                     ' ~~~ Validate the inputs
  140.                     strArgs = oProfileMgr.CreateArgs(strArgs)
  141.                 End If
  142.                 If Not IsNull(strArgs) Then
  143.                     If strArgs(0) = "1" Then
  144.                         StdOut.writeblanklines 1
  145.                         Wscript.Echo getResource("EmptyUser")
  146.                         Call oLog.Write ("ProfileMgr.wsf : username not provided")
  147.                         ProfileMgrQuitScript()
  148.                     End If
  149.                     If strArgs(0) = "4" Then
  150.                         StdOut.writeblanklines 1
  151.                         Wscript.Echo getResource("InvalidDrive")
  152.                         Call oLog.Write ("ProfileMgr.wsf : invalid drive")
  153.                         ProfileMgrQuitScript()
  154.                     End If
  155.                     If strArgs(0) = "5" Then
  156.                         StdOut.writeblanklines 1
  157.                         Wscript.Echo getResource("InvalidUser")
  158.                         Call oLog.Write ("ProfileMgr.wsf : " & getResource("InvalidUser"))
  159.                         ProfileMgrQuitScript()
  160.                     End If
  161.                     If strArgs(0) = "6" Then
  162.                         StdOut.writeblanklines 1
  163.                         Wscript.Echo getResource("InvalidDomain")
  164.                         Call oLog.Write ("ProfileMgr.wsf : Invalid Domain")
  165.                         ProfileMgrQuitScript()
  166.                     End If
  167.                     If strArgs(0) = "7" Then
  168.                         StdOut.writeblanklines 1
  169.                         Wscript.Echo getResource("ProfileExists")
  170.                         Call oLog.Write ("ProfileMgr.wsf : " & getResource("ProfileExists"))
  171.                         ProfileMgrQuitScript()
  172.                     End If
  173.                     If strArgs(0) = "8" Then
  174.                         StdOut.writeblanklines 1
  175.                         WScript.Echo getResource("DomainError")
  176.                         Call oLog.Write ("ProfileMgr.wsf : Invalid user or domain")
  177.                         ProfileMgrQuitScript()
  178.                     End If
  179.                     If oProfileMgr.CreateProfiles(strArgs(0),strArgs(1),strArgs(2),strArgs(3)) = 0 Then
  180.                         WScript.Echo getResource("CreateSuccess")
  181.                         Call oLog.Write("ProfileMgr.wsf : " & getResource("CreateSuccess"))
  182.                     Else
  183.                         WScript.Echo getResource("CreateFailure")
  184.                         Call oLog.Write("ProfileMgr.wsf : " & getResource("CreateFailure"))
  185.                         ProfileMgrQuitScript()
  186.                     End If    
  187.                 Else
  188.                     Call oLog.Write("ProfileMgr.wsf : " & getResource("IncorrectUsage"))
  189.                     ProfileMgrQuitScript()
  190.                 End If
  191.             End If
  192.             ' ~~~ --------------------------------------------------------------------------------
  193.             ' ~~~ Perform delete profile
  194.             ' ~~~ --------------------------------------------------------------------------------
  195.             If WScript.Arguments.Named.Exists("delete") Then
  196.                 Call oLog.Write("ProfileMgr.wsf : delete")
  197.                 bOK = True
  198.                 If args.count < 1 or args.count > 3 Then
  199.                     Call oLog.Write("ProfileMgr.wsf : " & getResource("IncorrectUsage"))
  200.                     ProfileMgrQuitScript()
  201.                  End If
  202.                  If args.count = 1 Then
  203.                           
  204.                      StdOut.write "Username:"
  205.                     sUser = StdIn.ReadLine
  206.                     StdOut.write "Domain:"
  207.                     sDomain = StdIn.ReadLine
  208.                     
  209.                     DeleteArgs = Array(sUser, sDomain)
  210.                      
  211.                      ' ~~~ Pass the arguments to class for check
  212.                      delArgs = oProfileMgr.DelArguments(DeleteArgs)
  213.                  Else
  214.                      delArgs = GetDeleteInputs()
  215.                      delArgs = oProfileMgr.DelArguments(delArgs)
  216.                  End If
  217.                 If Not IsNull(delArgs) Then
  218.                     If delArgs(0) = "1" Then
  219.                         StdOut.writeblanklines 1
  220.                         Wscript.Echo getResource("EmptyUser")
  221.                         Call oLog.Write("ProfileMgr.wsf : Username not provided")
  222.                         ProfileMgrQuitScript()
  223.                     End If
  224.                     If delArgs(0) = "2" Then
  225.                         StdOut.writeblanklines 1
  226.                         WScript.Echo getResource("LoggedOnUser")
  227.                         WScript.Echo getResource("CannotDelete")
  228.                         Call oLog.Write("ProfileMgr.wsf : Currently logged on User")
  229.                         ProfileMgrQuitScript()
  230.                     End If
  231.                     If delArgs(0) = "3" Then
  232.                         StdOut.writeblanklines 1
  233.                         WScript.Echo getResource("SwitchUser")
  234.                         WScript.Echo getResource("CannotDelete")
  235.                         Call oLog.Write("ProfileMgr.wsf : Currently logged on User")
  236.                         ProfileMgrQuitScript()
  237.                     End If
  238.                     If delArgs(0) = "5" Then
  239.                         StdOut.writeblanklines 1
  240.                         WScript.Echo getResource("InvalidUser")
  241.                         Call oLog.Write ("ProfileMgr.wsf : user not valid")
  242.                         ProfileMgrQuitScript()
  243.                     End If
  244.                     If delArgs(0) = "6" Then
  245.                         StdOut.writeblanklines 1
  246.                         WScript.Echo getResource("InvalidDomain")
  247.                         Call oLog.Write ("ProfileMgr.wsf : Invalid Domain")
  248.                         ProfileMgrQuitScript()
  249.                     End If
  250.                     If delArgs(0) = "7" Then
  251.                         StdOut.writeblanklines 1
  252.                         WScript.Echo getResource("NoProfile")
  253.                         Call oLog.Write ("ProfileMgr.wsf : No Profile")
  254.                         ProfileMgrQuitScript()
  255.                     End If
  256.                     If delArgs(0) = "8" Then
  257.                         StdOut.writeblanklines 1
  258.                         WScript.Echo getResource("DomainError")
  259.                         Call oLog.Write ("ProfileMgr.wsf : Invalid user or domain")
  260.                         ProfileMgrQuitScript()
  261.                     End If
  262.                     If oProfileMgr.deleteprofiles(delArgs(0),delArgs(1)) = "0" Then
  263.                         WScript.Echo getResource("DeleteSuccess")
  264.                     Else
  265.                         WScript.Echo getResource("DeleteFailure")
  266.                     End If    
  267.                 Else
  268.                     Call oLog.Write("ProfileMgr.wsf : " & getResource("IncorrectUsage"))
  269.                     ProfileMgrQuitScript()
  270.                 End If
  271.             End If
  272.             If Not(bOK) Then
  273.                 Call oLog.Write("ProfileMgr.wsf : " & getResource("IncorrectUsage"))
  274.                 ProfileMgrQuitScript()
  275.             End if
  276.             
  277.             ' ***
  278.             ' *** --------------------------------------------------------------------------------
  279.             ' *** Name:         ProfileMgrQuitScript()
  280.             ' *** --------------------------------------------------------------------------------
  281.             ' *** Purpose:        Used to show the usage and quit from script
  282.             ' *** --------------------------------------------------------------------------------
  283.             ' ***
  284.             Sub ProfileMgrQuitScript()
  285.                  WScript.Arguments.ShowUsage
  286.                  QuitScript()
  287.             End Sub
  288.             
  289.             ' ***
  290.             ' *** --------------------------------------------------------------------------------
  291.             ' *** Name:         GetCreateInputs()
  292.             ' *** --------------------------------------------------------------------------------
  293.             ' *** Purpose:        Parses the command line and returns the input arguments
  294.             ' ***            of the /create command
  295.             ' *** --------------------------------------------------------------------------------
  296.             ' ***
  297.             Function GetCreateInputs()
  298.                                     
  299.                 sUser = args(1)
  300.                 If WScript.Arguments.Named.Exists("domain") Then
  301.                     sDomain = WScript.Arguments.Named.Item("domain") 
  302.                 End If
  303.                 If WScript.Arguments.Named.Exists("drive") Then
  304.                     sDrive = WScript.Arguments.Named.Item("drive") 
  305.                 End If
  306.                 Select Case args.count
  307.                     Case 5
  308.                         sPassword = args(2)
  309.                     Case 3
  310.                         If sDomain = "" and sDrive = "" Then
  311.                             sPassword = args(2)
  312.                         End If
  313.                     Case 4
  314.                         If sDomain <> "" and sDrive <> "" Then
  315.                             sPassword = ""
  316.                         Else
  317.                             sPassword = args(2)
  318.                         End If
  319.                 End Select
  320.                 ' Return the inputs
  321.                 GetCreateInputs = Array(sUser, sPassword, sDomain, sDrive)
  322.             End Function
  323.             ' ***
  324.             ' *** --------------------------------------------------------------------------------
  325.             ' *** Name:         GetDeleteInputs()
  326.             ' *** --------------------------------------------------------------------------------
  327.             ' *** Purpose:        Parses the command line and returns the input arguments
  328.             ' ***            of the /delete command
  329.             ' *** --------------------------------------------------------------------------------
  330.             ' ***
  331.             Function GetDeleteInputs()
  332.                 sUser = args(1)
  333.                 If NOT WScript.Arguments.Named.Exists("domain") AND args.count = 3 Then
  334.                     StdOut.writeblanklines 1
  335.                     WScript.Echo getResource("IncorrectUsage")
  336.                     Call oLog.Write ("ProfileMgr.wsf : " & getResource("IncorrectUsage") )
  337.                     ProfileMgrQuitScript()
  338.                 End If
  339.                 
  340.                 If WScript.Arguments.Named.Exists("domain") Then
  341.                     sDomain = WScript.Arguments.Named.Item("domain") 
  342.                 End If    
  343.                 ' Return the inputs
  344.                 GetDeleteInputs = Array(sUser, sDomain)
  345.             End Function
  346.             
  347.             ' ~~~ ------------------------------------------------------------------------------
  348.             ' ~~~ Tidy up
  349.             ' ~~~ ------------------------------------------------------------------------------
  350.             ' ~~~ Close log
  351.             Call oLog.Close
  352.             ' ~~~ Destroy objects
  353.             Set oProfileMgr = nothing
  354.             Set oLog = nothing
  355.             UnLoadObjects()
  356.         ]]>
  357.         </script>
  358.     </job>
  359. </package>