home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2006 May / PCpro_2006_05.ISO / files / free_security / msshared / Shared_Computer_Toolkit_ENU.msi / FileInclude014 < prev    next >
Encoding:
Text (UTF-16)  |  2005-09-02  |  11.6 KB  |  174 lines

  1. ' *** 
  2. ' *** ------------------------------------------------------------------------------
  3. ' *** Filename:        libWSF.vbs
  4. ' *** ------------------------------------------------------------------------------
  5. ' *** Description:    Utility functions used by WSF files
  6. ' *** ------------------------------------------------------------------------------
  7. ' *** Version:        1.0
  8. ' *** Notes:        
  9. ' *** ------------------------------------------------------------------------------
  10. ' *** Copyright (C) Microsoft Corporation 2005, All Rights Reserved
  11. ' *** ------------------------------------------------------------------------------
  12. ' *** 
  13.  
  14. ' ~~~ 
  15. ' ~~~ Force variables to be declared 
  16. ' ~~~ 
  17. Option Explicit
  18.  
  19. ' *** 
  20. ' *** ------------------------------------------------------------------------------
  21. ' *** Name:            Main()
  22. ' *** ------------------------------------------------------------------------------
  23. ' *** Purpose:        Initialize the framework
  24. ' *** ------------------------------------------------------------------------------
  25. ' *** 
  26. Sub Main(sAppName)
  27.         
  28.     InitialiseAllObjects()
  29.  
  30.     If InSafeMode(False) = True Then
  31.         ' ~~~ Cannot be in Safe Mode when using this tool
  32.         QuitScript()
  33.     End If
  34.             
  35.     If sAppName <> "Accessibility.hta" Then
  36.         If IsAdministrator(False) = False Then
  37.             ' ~~~ Should be an administrator to use this tool
  38.             QuitScript()
  39.         End If
  40.     End If
  41.             
  42.     If sAppName <> "Accessibility.hta" Then
  43.         If CheckWGA(False) = False Then
  44.             ' ~~~ Should be validated for WGA
  45.             QuitScript()
  46.         End If    
  47.     End If
  48.     
  49.     If sAppName <> "" Then
  50.         If (IsAppRunning(sAppName)) = true Then
  51.             WScript.Echo "Please close the " & sAppName
  52.             QuitScript()
  53.         End If
  54.     End If
  55.             
  56.     ' ~~~ Call the forceScript function in libWSF.vbs to re-start the 
  57.     ' ~~~ script in command line
  58.     Call ForceCScript
  59.  
  60. End Sub
  61.  
  62. ' *** 
  63. ' *** ------------------------------------------------------------------------------
  64. ' *** Name:            GetUnnamedArgument(i)
  65. ' *** ------------------------------------------------------------------------------
  66. ' *** Purpose:        Gets the numbered argument from the unnamed collection
  67. ' ***                 ?f the numbered argument does not exist, a null string is ret
  68. ' *** ------------------------------------------------------------------------------
  69. ' *** 
  70. Function GetUnnamedArgument(i)
  71.     If WScript.Arguments.Unnamed.Count >= i Then
  72.         GetUnnamedArgument = WScript.Arguments.Unnamed(i-1)
  73.     Else
  74.         GetUnnamedArgument = ""
  75.     End If
  76. End Function
  77.  
  78. ' *** 
  79. ' *** ------------------------------------------------------------------------------
  80. ' *** Name:            DisplayActionStatus(bStatus)
  81. ' *** ------------------------------------------------------------------------------
  82. ' *** Purpose:        Displays the status returned by an action routine
  83. ' *** ------------------------------------------------------------------------------
  84. ' *** 
  85. Sub DisplayActionStatus(bStatus, sActionGood, sActionBad)
  86.     If bStatus Then
  87.         WScript.Echo sActionGood
  88.     Else                
  89.         WScript.Echo sActionBad
  90.         QuitScript()
  91.     End If
  92. End Sub
  93.  
  94. ' *** 
  95. ' *** ------------------------------------------------------------------------------
  96. ' *** Name:            GetRootFolder
  97. ' *** ------------------------------------------------------------------------------
  98. ' *** Purpose:        Returns the application root folder (location of .HTA files)
  99. ' *** ------------------------------------------------------------------------------
  100. ' *** 
  101. Function GetRootFolder
  102.     GetRootFolder = Left(WScript.ScriptFullName, Len(WScript.ScriptFullName) - Len("\Scripts\" & WScript.ScriptName))
  103. End Function
  104.  
  105. ' *** 
  106. ' *** ------------------------------------------------------------------------------
  107. ' *** Name:            GetFilename
  108. ' *** ------------------------------------------------------------------------------
  109. ' *** Purpose:        Returns the application filename with the .wsf removed
  110. ' *** ------------------------------------------------------------------------------
  111. ' *** 
  112. Function GetFilename
  113.     Dim sCmd, iSlash, iDot
  114.  
  115.     sCmd   = Wscript.ScriptFullname
  116.  
  117.     iSlash = InStrRev(sCmd, "\")+1
  118.     iDot   = InStrRev(sCmd, ".")
  119.     GetFilename = Mid(sCmd, iSlash, iDot-iSlash)
  120.  
  121. End Function
  122.  
  123. ' *** 
  124. ' *** ------------------------------------------------------------------------------
  125. ' *** Name:            ForceCScript
  126. ' *** ------------------------------------------------------------------------------
  127. ' *** Purpose:        This function runs the wsf scripts in command line
  128. ' ***                if the default script host is wscript.exe.
  129. ' *** ------------------------------------------------------------------------------
  130. ' *** 
  131. Function ForceCScript
  132.     Dim strCMD, oArgs, i
  133.     
  134.     If Lcase(Right(Wscript.FullName, 12)) = "\wscript.exe" Then 
  135.     
  136.         ' ~~~ Start the command-line that we will re-start
  137.         strCMD = "CMD /K CScript.exe " & Chr(34) & Wscript.ScriptFullName & Chr(34)
  138.             
  139.         Set oArgs = Wscript.Arguments
  140.     
  141.         ' ~~~ Loop through all arguments and add them to the command-line
  142.         For i = 0 to oArgs.Count - 1
  143.     
  144.             If InStr(oArgs(i), " ") > 0 Then
  145.                 ' ~~~ If there's a space in the argument, surround it with quotes
  146.                 strCMD = strCMD & " " & Chr(34) & oArgs(i) & Chr(34)
  147.             Else
  148.                 strCMD = strCMD & " " & oArgs(i)
  149.             End If
  150.         Next
  151.     
  152.         ' ~~~ Running in Wscript - need to re-start the command-line and exit this script
  153.         Call oShell.Run(strCMD, 10, False)
  154.         
  155.         Call oShell.Popup(getResource("CScriptMessage"), 0, getResource("CScriptTitle"), 64)
  156.                 
  157.         QuitScript()
  158.         
  159.     End If 
  160.     
  161. End Function
  162.  
  163. ' *** 
  164. ' *** ------------------------------------------------------------------------------
  165. ' *** Name:            QuitScript()
  166. ' *** ------------------------------------------------------------------------------
  167. ' *** Purpose:        Quits the script and unload all the objects
  168. ' *** ------------------------------------------------------------------------------
  169. ' *** 
  170.  
  171. Sub QuitScript()
  172.     UnLoadObjects()
  173.     Wscript.Quit
  174. End Sub