home *** CD-ROM | disk | FTP | other *** search
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Filename: libWSF.vbs
- ' *** ------------------------------------------------------------------------------
- ' *** Description: Utility functions used by WSF files
- ' *** ------------------------------------------------------------------------------
- ' *** Version: 1.0
- ' *** Notes:
- ' *** ------------------------------------------------------------------------------
- ' *** Copyright (C) Microsoft Corporation 2005, All Rights Reserved
- ' *** ------------------------------------------------------------------------------
- ' ***
-
- ' ~~~
- ' ~~~ Force variables to be declared
- ' ~~~
- Option Explicit
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: Main()
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Initialize the framework
- ' *** ------------------------------------------------------------------------------
- ' ***
- Sub Main(sAppName)
-
- InitialiseAllObjects()
-
- If InSafeMode(False) = True Then
- ' ~~~ Cannot be in Safe Mode when using this tool
- QuitScript()
- End If
-
- If sAppName <> "Accessibility.hta" Then
- If IsAdministrator(False) = False Then
- ' ~~~ Should be an administrator to use this tool
- QuitScript()
- End If
- End If
-
- If sAppName <> "Accessibility.hta" Then
- If CheckWGA(False) = False Then
- ' ~~~ Should be validated for WGA
- QuitScript()
- End If
- End If
-
- If sAppName <> "" Then
- If (IsAppRunning(sAppName)) = true Then
- WScript.Echo "Please close the " & sAppName
- QuitScript()
- End If
- End If
-
- ' ~~~ Call the forceScript function in libWSF.vbs to re-start the
- ' ~~~ script in command line
- Call ForceCScript
-
- End Sub
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: GetUnnamedArgument(i)
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Gets the numbered argument from the unnamed collection
- ' *** ?f the numbered argument does not exist, a null string is ret
- ' *** ------------------------------------------------------------------------------
- ' ***
- Function GetUnnamedArgument(i)
- If WScript.Arguments.Unnamed.Count >= i Then
- GetUnnamedArgument = WScript.Arguments.Unnamed(i-1)
- Else
- GetUnnamedArgument = ""
- End If
- End Function
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: DisplayActionStatus(bStatus)
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Displays the status returned by an action routine
- ' *** ------------------------------------------------------------------------------
- ' ***
- Sub DisplayActionStatus(bStatus, sActionGood, sActionBad)
- If bStatus Then
- WScript.Echo sActionGood
- Else
- WScript.Echo sActionBad
- QuitScript()
- End If
- End Sub
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: GetRootFolder
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Returns the application root folder (location of .HTA files)
- ' *** ------------------------------------------------------------------------------
- ' ***
- Function GetRootFolder
- GetRootFolder = Left(WScript.ScriptFullName, Len(WScript.ScriptFullName) - Len("\Scripts\" & WScript.ScriptName))
- End Function
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: GetFilename
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Returns the application filename with the .wsf removed
- ' *** ------------------------------------------------------------------------------
- ' ***
- Function GetFilename
- Dim sCmd, iSlash, iDot
-
- sCmd = Wscript.ScriptFullname
-
- iSlash = InStrRev(sCmd, "\")+1
- iDot = InStrRev(sCmd, ".")
- GetFilename = Mid(sCmd, iSlash, iDot-iSlash)
-
- End Function
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: ForceCScript
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: This function runs the wsf scripts in command line
- ' *** if the default script host is wscript.exe.
- ' *** ------------------------------------------------------------------------------
- ' ***
- Function ForceCScript
- Dim strCMD, oArgs, i
-
- If Lcase(Right(Wscript.FullName, 12)) = "\wscript.exe" Then
-
- ' ~~~ Start the command-line that we will re-start
- strCMD = "CMD /K CScript.exe " & Chr(34) & Wscript.ScriptFullName & Chr(34)
-
- Set oArgs = Wscript.Arguments
-
- ' ~~~ Loop through all arguments and add them to the command-line
- For i = 0 to oArgs.Count - 1
-
- If InStr(oArgs(i), " ") > 0 Then
- ' ~~~ If there's a space in the argument, surround it with quotes
- strCMD = strCMD & " " & Chr(34) & oArgs(i) & Chr(34)
- Else
- strCMD = strCMD & " " & oArgs(i)
- End If
- Next
-
- ' ~~~ Running in Wscript - need to re-start the command-line and exit this script
- Call oShell.Run(strCMD, 10, False)
-
- Call oShell.Popup(getResource("CScriptMessage"), 0, getResource("CScriptTitle"), 64)
-
- QuitScript()
-
- End If
-
- End Function
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: QuitScript()
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Quits the script and unload all the objects
- ' *** ------------------------------------------------------------------------------
- ' ***
-
- Sub QuitScript()
- UnLoadObjects()
- Wscript.Quit
- End Sub