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

  1.  ■<?xml version="1.0" ?>
  2. <package>
  3.     <comment>
  4.         ' *** 
  5.         ' *** ------------------------------------------------------------------------------
  6.         ' *** Filename:        AutoRunOnce.wsf
  7.         ' *** ------------------------------------------------------------------------------
  8.         ' *** Description:    Command line tool to cause a User Profile to Run a program
  9.         ' ***             once upon logon.
  10.         ' *** ------------------------------------------------------------------------------
  11.         ' *** Version:        1.0
  12.         ' *** Notes:        
  13.         ' *** ------------------------------------------------------------------------------
  14.         ' *** Copyright (C) Microsoft Corporation 2005, All Rights Reserved
  15.         ' *** ------------------------------------------------------------------------------
  16.         ' ***
  17.     </comment>
  18.     <job>
  19.     <runtime>
  20.             <description>AutoRunOnce Script</description>
  21.             <named name="user" required="false" helpstring="Name a user for the AutoRunOnce command" />
  22.             <named name="add" required="false" helpstring="Add a RunOnce command" />
  23.             <named name="args" required="false" helpstring="Arguments for a RunOnce command" />
  24.             <named name="remove" required="false" helpstring="Remove a RunOnce command" />
  25.             <named name="list" required="false" helpstring="List RunOnce commands" />
  26.             <example>
  27. Examples:
  28. AutoRunOnce.wsf /add:RunOnceKey /user:Public
  29.   "C:\Program Files\Microsoft Shared Computer Toolkit\Scripts\AutoDemo" 
  30.   /args:"/Step2"
  31. AutoRunOnce.wsf /add:RunOnceKey 
  32.   "C:\Program Files\Microsoft Shared Computer Toolkit\Scripts\AutoDemo" 
  33.   /args:"/Step3 admin password"
  34. AutoRunOnce.wsf /remove:RunOnceKey /user:Public
  35. AutoRunOnce.wsf /remove:RunOnceKey
  36. AutoRunOnce.wsf /list /user:Public
  37. AutoRunOnce.wsf /list</example>
  38.         </runtime>
  39.     
  40.         <resource id="IncorrectUsage">Incorrect Usage Detected</resource>
  41.         <resource id="ScriptName">AutoRunOnce.wsf</resource>
  42.         <resource id="AddSuccess">RunOnce command has been added.</resource>
  43.         <resource id="AddFail">RunOnce command could not be added.</resource>
  44.         <resource id="RemoveSuccess">RunOnce command has been removed.</resource>
  45.         <resource id="RemoveFail">RunOnce command not removed; it did not exist.</resource>
  46.         <resource id="ListTitle">RunOnce commands (key    type    value):</resource>
  47.         <resource id="ListEmpty">No RunOnce commands found.</resource>
  48.         <resource id="InvalidUser">Unable to open the registry for this user.</resource>
  49.         <resource id="AdminErrorMsg">You have to be an administrator to use this script.</resource>
  50.         <resource id="ErrorMessage">Could not modify the user registry successfully.</resource>
  51.         <resource id="CScriptMessage">Restarting script in command-line mode. Run CmdOn.BAT to set command-line mode as the default mode.</resource>
  52.         <resource id="CScriptTitle">Shared Computer Toolkit: Windows Script Mode Detected</resource>
  53.                 
  54.     <?job error="true" debug="false" ?>
  55.     
  56.         <script language="VBScript" src="../include/Common.vbs"></script>
  57.         <script language="VBScript" src="../include/libWSF.vbs"></script>
  58.         <script language="VBScript" src="../include/clsLogging.vbs"></script>
  59.         <script language="VBScript" src="../include/clsRestrictions.vbs"></script>
  60.         <script language="VBScript">
  61.         <![CDATA[
  62.             ' ~~~ 
  63.             ' ~~~ Force variables to be declared 
  64.             ' ~~~ 
  65.             Option Explicit
  66.             On Error Goto 0
  67.             ' ~~~ Call the Main 
  68.             Call Main("")
  69.             ' ~~~ 
  70.             ' ~~~ Declare variables and constants
  71.             ' ~~~ 
  72.             Const RUNKEY1 = "HKEY_USERS\SSW\Software\Microsoft\Windows\CurrentVersion\RunOnce"
  73.             Const RUNKEY2 = "HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce"
  74.         
  75.             Dim oLog, bOK, args, bResult, oExec
  76.             Dim strUser, strKey, strTemp
  77.             ' ~~~ Call the forceScript function in libWSF.vbs to re-start the 
  78.             ' ~~~ script in command line
  79.             Call ForceCScript
  80.             ' ~~~ ------------------------------------------------------------------------------
  81.             ' ~~~ Logging
  82.             ' ~~~ ------------------------------------------------------------------------------
  83.             Set oLog = New Logging
  84.             Call oLog.Open(GetRootFolder & "\log\AutoRunOnce.wsf.log")
  85.             Call oLog.Write("AutoRunOnce.wsf : Started")
  86.             ' ~~~ ------------------------------------------------------------------------------
  87.             ' ~~~ Check Script Usage
  88.             ' ~~~ ------------------------------------------------------------------------------
  89.             strKey = ""
  90.             bOK = False
  91.             Set args = WScript.Arguments
  92.             
  93.             If args.Named.Exists("add")    and args.Named.Item("add")    <> "" and (args.Unnamed.Count = 1 or args.Unnamed.Count = 2) Then 
  94.                 bOK = True
  95.                 strKey = args.Named.Item("add")
  96.                 If args.Named.Exists("remove") or args.Named.Exists("list") Then bOK = False
  97.             End If
  98.             If args.Named.Exists("remove") and args.Named.Item("remove") <> "" and args.Unnamed.Count = 0 Then
  99.                 bOK = True
  100.                 strKey = args.Named.Item("remove")
  101.                 If args.Named.Exists("add") or args.Named.Exists("list") Then bOK = False
  102.             End If
  103.             If args.Named.Exists("list")   and args.Named.Item("list")    = "" and args.Unnamed.Count = 0 Then 
  104.                 bOK = True
  105.                 If args.Named.Exists("add") Then bOK = False
  106.             End If
  107.             
  108.             If Not(bOK) Then
  109.                 Call oLog.Write(getResource("ScriptName") & " : " & getResource("IncorrectUsage"))
  110.                 WScript.Arguments.Showusage
  111.                 QuitScript()
  112.             End If
  113.             strUser = ""
  114.             strUser = args.Named.Item("user")
  115.             If strUser <> "" Then
  116.                 ' ~~~ If a user has been identified, attempt to load their hive
  117.                 Dim oRestrict
  118.                 Set oRestrict = New Restriction
  119.                 ' ~~~ ------------------------------------------------------------------------------
  120.                 ' ~~~ Load the user's registry hive
  121.                 ' ~~~ ------------------------------------------------------------------------------
  122.                 If NOT oRestrict.LoadUser(strUser) Then
  123.                     Call oLog.Write(getResource("ScriptName") & " : " & getResource("InvalidUser"))
  124.                     WScript.Echo getResource("InvalidUser")
  125.                     QuitScript()
  126.                 End If
  127.                 strKey = RUNKEY1 & "\" & strKey
  128.             Else
  129.                 ' ~~~ If a user was not identified, use HKCU
  130.                 strKey = RUNKEY2 & "\" & strKey
  131.             End If
  132.             
  133.             ' ~~~ ------------------------------------------------------------------------------
  134.             ' ~~~ Now do add/remove/list
  135.             ' ~~~ ------------------------------------------------------------------------------
  136.             ' ~~~ We need to catch error codes below
  137.             On Error Resume Next
  138.             ' ~~~ Add an AutoRunOnce on the account 
  139.             If args.Named.Exists("add") Then
  140.                 If args.Named.Exists("args") Then
  141.                     strTemp = Chr(34) & args.Unnamed.Item(0) & Chr(34) & " " & args.Named.Item("args")
  142.                 Else
  143.                     strTemp = Chr(34) & args.Unnamed.Item(0) & Chr(34) 
  144.                 End If
  145.                 RegWrite strKey, strTemp, "REG_EXPAND_SZ"
  146.                 If err.number = 0 Then 
  147.                     Call oLog.Write("add : " & getResource("AddSuccess"))
  148.                     WScript.Echo getResource("AddSuccess")
  149.                 Else
  150.                     Call oLog.Write("add : " & getResource("AddFail"))
  151.                     WScript.Echo getResource("AddFail")
  152.                 End If
  153.             End If
  154.             
  155.             ' ~~~ Disable AutoRunOnce on the account
  156.             If args.Named.Exists("remove") Then
  157.                 oShell.RegDelete strKey
  158.                 If err.number = 0 Then 
  159.                     Call oLog.Write("remove : " & getResource("RemoveSuccess"))
  160.                     WScript.Echo getResource("RemoveSuccess")
  161.                 Else
  162.                     Call oLog.Write("remove : " & getResource("RemoveFail"))
  163.                     WScript.Echo getResource("RemoveFail")
  164.                 End If
  165.             End If
  166.             If Wscript.Arguments.Named.Exists("list") Then
  167.                 Call oLog.Write("list : " & getResource("ListTitle"))
  168.                 Wscript.Echo GetResource("ListTitle")
  169.                 Set oExec = oShell.Exec("REG QUERY " & Chr(34) & strKey & Chr(34) & " /s")
  170.                 bResult = 0
  171.                 Do While oExec.Status = 0
  172.                     strTemp = oExec.StdOut.Readline
  173.                     If strTemp <> "" and Left(strTemp,1) = " " Then 
  174.                         WScript.Echo strTemp
  175.                         Call oLog.Write("list : " & strTemp)
  176.                         bResult = bResult + 1
  177.                     End If
  178.                 Loop
  179.                 If bResult = 0 Then 
  180.                     Call oLog.Write("list : " & getResource("ListEmpty"))
  181.                     WScript.Echo getResource("ListEmpty")
  182.                 End If
  183.                 
  184.             End If
  185.             ' ~~~ ------------------------------------------------------------------------------
  186.             ' ~~~ Unload the user's registry hive
  187.             ' ~~~ ------------------------------------------------------------------------------
  188.             If strUser <> "" Then oRestrict.UnLoadUser
  189.             
  190.             ' ~~~ Destroy objects
  191.             Call oLog.Close
  192.             Set oLog = Nothing
  193.             UnLoadObjects()
  194.             
  195.         ]]>
  196.         </script>
  197.     </job>
  198. </package>