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

  1.  ■<?xml version="1.0" ?>
  2. <package>
  3.     <comment>
  4.         ' *** 
  5.         ' *** ------------------------------------------------------------------------------
  6.         ' *** Filename:        AutoRestart.wsf
  7.         ' *** ------------------------------------------------------------------------------
  8.         ' *** Description:    Command line tool to cause a User Profile to monitor for and
  9.         ' ***             restart a specific program if it is closed.
  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>AutoRestart Script</description>
  21.             <named name="enable" required="false" many="false" helpstring="Enable AutoRestart for an account with a specific program" />
  22.             <named name="disable" required="false" many="false" helpstring="Disable AutoRestart for an account" />
  23.             <named name="list" required="false" many="false" helpstring="List AutoRestart command for an account" />
  24.             <example>
  25. Examples:
  26. AutoRestart.wsf /enable Public "C:\Program Files\Internet Explorer\IExplore.exe"
  27. AutoRestart.wsf /disable Public
  28. AutoRestart.wsf /list Public</example>
  29.         </runtime>
  30.     
  31.         <resource id="IncorrectUsage">Incorrect Usage Detected</resource>
  32.         <resource id="ScriptName">AutoRestart.wsf</resource>
  33.         <resource id="EnableSuccess">AutoRestart has been enabled for the user. AutoRestart command:</resource>
  34.         <resource id="DisableSuccess">AutoRestart has been disabled for the user.</resource>
  35.         <resource id="ListSuccess">AutoRestart command for this account:</resource>
  36.         <resource id="ListError">There is no AutoRestart command for this account.</resource>
  37.         <resource id="InvalidUser">Unable to open the registry for this account.</resource>
  38.         <resource id="InvalidUser2">The account is either logged in or does not exist.</resource>
  39.         <resource id="AdminErrorMsg">You have to be an administrator to use this script.</resource>
  40.         <resource id="NoToolkit">The Toolkit path cannot be found. Please reinstall the Toolkit.</resource>
  41.         <resource id="ErrorMessage">Could not modify the user registry successfully.</resource>
  42.         <resource id="CScriptMessage">Restarting script in command-line mode. Run CmdOn.BAT to set command-line mode as the default mode.</resource>
  43.         <resource id="CScriptTitle">Shared Computer Toolkit: Windows Script Mode Detected</resource>
  44.                 
  45.         <?job error="True" debug="False" ?>
  46.     
  47.         <script language="VBScript" src="../include/Common.vbs"></script>
  48.         <script language="VBScript" src="../include/libWSF.vbs"></script>
  49.         <script language="VBScript" src="../include/clsLogging.vbs"></script>
  50.         <script language="VBScript" src="../include/clsRestrictions.vbs"></script>
  51.         <script language="VBScript">
  52.         <![CDATA[
  53.             ' ~~~ 
  54.             ' ~~~ Force variables to be declared 
  55.             ' ~~~ 
  56.             Option Explicit
  57.             
  58.             On Error Goto 0
  59.             ' ~~~ Call the Main 
  60.             Call Main("")
  61.             
  62.             ' ~~~ 
  63.             ' ~~~ Declare variables and constants
  64.             ' ~~~ 
  65.             Dim oRestrict, oLog , bOK, args, sAppDir, sCMD
  66.             
  67.             Const TARGETDIR = "HKLM\Software\Microsoft\Shared Computer Toolkit\TargetDir"
  68.             Const RUNCMD = "bin\AutoRestart.vbs"
  69.             Const RUNKEY = "HKEY_USERS\SSW\Software\Microsoft\Windows\CurrentVersion\Run\SCTRunAutoRestart"
  70.             Set oRestrict = New Restriction
  71.             
  72.             ' ~~~ ------------------------------------------------------------------------------
  73.             ' ~~~ Logging
  74.             ' ~~~ ------------------------------------------------------------------------------
  75.             ' ~~~ Create logging object
  76.             Set oLog = New Logging
  77.             ' ~~~ Initiate logging
  78.             Call oLog.Open(GetRootFolder & "\log\AutoRestart.wsf.log")
  79.             Call oLog.Write("AutoRestart.wsf : Started")
  80.             
  81.             
  82.             ' ~~~ ------------------------------------------------------------------------------
  83.             ' ~~~ Check script usage
  84.             ' ~~~ ------------------------------------------------------------------------------
  85.             bOK = False
  86.             Set args = WScript.Arguments
  87.             
  88.             If Wscript.Arguments.Named.Exists("enable") and args.Count = 3 Then bOK = True
  89.             If Wscript.Arguments.Named.Exists("disable") and args.Count = 2 Then bOK = True
  90.             If Wscript.Arguments.Named.Exists("list") and args.Count = 2 Then bOK = True
  91.             
  92.             If Not(bOK) Then
  93.                 Call oLog.Write(getResource("ScriptName") & " : " & getResource("IncorrectUsage"))
  94.                 Wscript.Echo getResource("IncorrectUsage")
  95.                 WScript.Arguments.Showusage
  96.                 QuitScript()
  97.             End If
  98.             ' ~~~ ------------------------------------------------------------------------------
  99.             ' ~~~ Read the TargetDir for the Toolkit
  100.             ' ~~~ ------------------------------------------------------------------------------
  101.             ' ~~~ Need to check error returns here
  102.             On Error Resume Next
  103.             sAppDir = ""
  104.             sAppDir = oShell.RegRead(TARGETDIR)
  105.             If Err.number <> 0 Then 
  106.                 Call oLog.Write(getResource("ScriptName") & " : " & getResource("NoToolkit"))
  107.                 Wscript.Echo getResource("NoToolkit")
  108.                 WScript.Arguments.Showusage
  109.                 QuitScript()
  110.             End If
  111.             On Error Goto 0
  112.             ' ~~~ ------------------------------------------------------------------------------
  113.             ' ~~~ Load the user's registry hive
  114.             ' ~~~ ------------------------------------------------------------------------------
  115.             
  116.             If NOT oRestrict.LoadUser(args(1)) Then
  117.                 Call oLog.Write(getResource("ScriptName") & " : " & getResource("InvalidUser"))
  118.                 WScript.Echo getResource("InvalidUser")
  119.                 WScript.Echo getResource("InvalidUser2")
  120.                 WScript.Echo
  121.                 QuitScript()
  122.             End If
  123.             ' ~~~ ------------------------------------------------------------------------------
  124.             ' ~~~ Now do enable/disable
  125.             ' ~~~ ------------------------------------------------------------------------------
  126.             ' ~~~ We need to catch error codes below
  127.             On Error Resume Next
  128.             ' ~~~ Enable AutoRestart on the account 
  129.             If Wscript.Arguments.Named.Exists("enable") Then
  130.                 Err.Clear
  131.                 RegWrite RUNKEY, "%windir%\system32\WScript.EXE " & chr(34) & sAppDir & RUNCMD & Chr(34) & " " & Chr(34) & args(2) & Chr(34), "REG_EXPAND_SZ"
  132.                 If err.number = 0 Then 
  133.                     Call oLog.Write("enable : " & getResource("EnableSuccess"))
  134.                     WScript.Echo getResource("EnableSuccess")
  135.                     WScript.Echo "%windir%\system32\WScript.EXE " & chr(34) & sAppDir & RUNCMD & Chr(34) & " " & Chr(34) & args(2) & Chr(34)
  136.                 Else
  137.                     Call oLog.Write("enable : " & getResource("ErrorMessage"))
  138.                     WScript.Echo getResource("ErrorMessage")
  139.                 End If
  140.             End If
  141.             
  142.             ' ~~~ Disable AutoRestart on the account
  143.             If Wscript.Arguments.Named.Exists("disable") Then
  144.                 Err.Clear
  145.                 oShell.RegDelete RUNKEY
  146.                 If err.number = 0 or err.number = -2147024894 Then 
  147.                     Call oLog.Write("enable : " & getResource("DisableSuccess"))
  148.                     WScript.Echo getResource("DisableSuccess")
  149.                 Else
  150.                     Call oLog.Write("enable : " & getResource("ErrorMessage"))
  151.                     WScript.Echo getResource("ErrorMessage")
  152.                 End If
  153.             End If
  154.             If Wscript.Arguments.Named.Exists("list") Then
  155.                 Err.Clear
  156.                 sCMD = oShell.RegRead(RUNKEY)
  157.                 If err.number = 0 Then 
  158.                     Wscript.Echo GetResource("ListSuccess")
  159.                     Wscript.Echo sCMD
  160.                 Else
  161.                     Wscript.Echo GetResource("ListError")
  162.                 End If
  163.             End If
  164.             On Error Goto 0
  165.             ' ~~~ ------------------------------------------------------------------------------
  166.             ' ~~~ Unload the user's registry hive
  167.             ' ~~~ ------------------------------------------------------------------------------
  168.             oRestrict.UnLoadUser
  169.             ' ~~~ Close log
  170.             Call oLog.Close
  171.             
  172.             ' ~~~ Destroy objects
  173.             Set oLog = nothing
  174.             UnLoadObjects()
  175.             
  176.         ]]>
  177.         </script>
  178.     </job>
  179. </package>