home *** CD-ROM | disk | FTP | other *** search
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Filename: clsAccessibility.vbs
- ' *** ------------------------------------------------------------------------------
- ' *** Description: Accessibility Class
- ' *** ------------------------------------------------------------------------------
- ' *** Version: 1.0
- ' *** Notes:
- ' *** ------------------------------------------------------------------------------
- ' *** Copyright (C) Microsoft Corporation 2005, All Rights Reserved
- ' *** ------------------------------------------------------------------------------
- ' ***
-
- ' ~~~
- ' ~~~ Force variables to be declared and turn off script error messages unless in DEBUG mode
- ' ~~~
- Option Explicit
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
-
- Class accessibility
-
- ' ~~~
- ' ~~~ declare global variables and constants
- ' ~~~
- Dim bLogging, strAccessibility, HKEY
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Property: Logging
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Turns on logging, property must be set to a logging object
- ' *** ------------------------------------------------------------------------------
- ' ***
- Public Property Get Logging
- Logging = bLogging
- End Property
-
- Public Property Let Logging(oObject)
- If VarType(oObject) = vbObject Then
- bLogging = True
- Set oLog = oObject
- End If
- End Property
-
-
- ' ~~~
- ' ~~~ public methods
- ' ~~~
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: CloseApplication()
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Close the Application corresponding to the unselect of the option
- ' *** ------------------------------------------------------------------------------
- ' ***
- Public Function CloseApplication()
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
-
- Dim MagnifyProcID, colProcesses, oProcess
- MagnifyProcID = ""
- Set colProcesses = oWMIService.ExecQuery ("SELECT * FROM Win32_Process WHERE Name = 'magnify.exe'")
-
- If colProcesses.Count > 0 Then
- For Each oProcess in colProcesses
- MagnifyProcID = oProcess.ProcessId
- Next
- End If
-
- If MagnifyProcID <> "" Then
- oShell.AppActivate MagnifyProcID
- oShell.SendKeys ("%{F4}")
- End If
-
- End Function
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: End_Process(Process_Name)
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Terminate the Process corresponding to the unselect of the option
- ' *** ------------------------------------------------------------------------------
- ' ***
- Public Function End_Process(Process_Name)
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
-
- Dim colProcesses, oProcess
- Set colProcesses = oWMIService.ExecQuery _
- ("Select * from Win32_Process Where Name = '" & Process_Name & "'")
- For Each oProcess in colProcesses
- oProcess.Terminate
- Next
- End Function
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: Start_Process(objID)
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Starts the process corresponding to the option selected
- ' *** ------------------------------------------------------------------------------
- ' ***
- Public Function Start_Process(objID)
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
-
- Dim processName
- processName = Get_ProcessName(objID)
- Select Case objID
- Case "magnifier"
- Call RegWrite(HKEY & "Magnify\ShowWarning",0,"REG_DWORD")
- Call RegWrite(HKEY & "Magnify\StationaryStartMinimized",1,"REG_DWORD")
- Case "narrator"
- Call RegWrite(HKEY & "Narrator\ShowWarning",0,"REG_DWORD")
- Call RegWrite(HKEY & "Narrator\StartType",1,"REG_DWORD")
- Case "oskeyboard"
- HideOSKeyWarning()
- End Select
- oShell.Run processName, 0, False
-
- End Function
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: Get_ProcessName(proID)
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Gets the name of the process for the option that is selected
- ' *** ------------------------------------------------------------------------------
- ' ***
- Public Function Get_ProcessName(proID)
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
-
- If proID = "magnifier" Then
- Get_ProcessName = "Magnify.exe"
- ElseIf proID = "narrator" Then
- Get_ProcessName = "Narrator.exe"
- ElseIf proID = "oskeyboard" Then
- Get_ProcessName = "OSK.exe"
- Else
- Get_ProcessName = ""
- End If
-
- End Function
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: Get_ProcessStatus(proId)
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Gets the status of the exe's that are
- ' *** currently running for the option that is selected
- ' *** ------------------------------------------------------------------------------
- ' ***
- Public Function Get_ProcessStatus(proId)
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
-
- Dim sProcessName, colProcesses, oProcess
- Get_ProcessStatus = False
- sProcessName = Get_ProcessName(proId)
- Set colProcesses = oWMIService.ExecQuery _
- ("Select * from Win32_Process Where Name = '" & sProcessName & "'")
- For Each oProcess in colProcesses
- Get_ProcessStatus = True
- Next
- End Function
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: GetOption(sOption)
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Returns 1 if the option is enabled or 0 if it is disabled.
- ' *** ------------------------------------------------------------------------------
- ' ***
- Public Function GetOption(sOption)
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
-
- Dim scmd
-
- Select Case (sOption)
- Case "contrast"
- scmd = strAccessibility & " " & "GetContrast"
- GetOption = ShellRun (scmd)
-
- Case "largepointer"
- scmd = strAccessibility & " " & "GetLargeCursor"
- GetOption = ShellRun (scmd)
-
- Case "soundsentry"
- scmd = strAccessibility & " " & "GetSoundSentry"
- GetOption = ShellRun (scmd)
-
- Case "showsound"
- scmd = strAccessibility & " " & "GetShowSound"
- GetOption = ShellRun (scmd)
-
- Case "stickykeys"
- scmd = strAccessibility & " " & "GetStickyKeys"
- GetOption = ShellRun (scmd)
-
- Case "filterkeys"
- scmd = strAccessibility & " " & "GetFilterKeys"
- GetOption = ShellRun (scmd)
-
- Case "mousekeys"
- scmd = strAccessibility & " " & "GetMouseKeys"
- GetOption = ShellRun (scmd)
-
- End Select
-
- End Function
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: SetOption(sOption, bEnable)
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Gets the feature name as input and return whether it is
- ' *** enabled(1) or disabled(0)
- ' *** ------------------------------------------------------------------------------
- ' ***
- Public Function SetOption(sOption, bEnable)
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
-
- Dim strCmd
- Select Case (sOption)
- Case "contrast"
- strCmd = strAccessibility & " " & "SetContrast" & " " & bEnable
- ShellRun strCmd
- Exit Function
- Case "largepointer"
- strCmd = strAccessibility & " " & "SetLargeCursor" & " " & bEnable
- ShellRun strCmd
- Exit Function
- Case "soundsentry"
- strCmd = strAccessibility & " " & "SetSoundSentry" & " " & bEnable
- ShellRun strCmd
- Exit Function
- Case "showsound"
- strCmd = strAccessibility & " " & "SetShowSound" & " " & bEnable
- ShellRun strCmd
- Exit Function
- Case "stickykeys"
- strCmd = strAccessibility & " " & "SetStickyKeys" & " " & bEnable
- ShellRun strCmd
- Exit Function
- Case "filterkeys"
- strCmd = strAccessibility & " " & "SetFilterKeys" & " " & bEnable
- ShellRun strCmd
- Exit Function
- Case "mousekeys"
- strCmd = strAccessibility & " " & "SetMouseKeys" & " " & bEnable
- ShellRun strCmd
- Exit Function
- End Select
-
- End Function
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: Advanced()
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Called to display the Advanced accessibility options
- ' *** ------------------------------------------------------------------------------
- ' ***
- Public Function Advanced()
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
-
- Dim sysDirectory
-
- ' ~~~ Get the system root directory
- sysDirectory = oShell.ExpandEnvironmentStrings("%SYSTEMROOT%")
- sysDirectory = sysDirectory & "\system32"
-
- ' ~~~ Run the Control Panel Applet using the control.exe
- oShell.run "control.exe " & sysDirectory & "\access.cpl",1,False
- End Function
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: GetContrastThemes(bCalledFrom, sContrast)
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Used by both HTA and Wsf to get the high contrast themes
- ' *** from registry
- ' *** ------------------------------------------------------------------------------
- ' ***
- Public Function GetContrastThemes(bCalledFrom, sContrast)
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
-
- Dim strComputer, oReg, strKeyPath
- Dim arrValueNames, arrValueTypes, iTheme
-
- GetContrastThemes = ""
-
- const HKEY_CURRENT_USER = &H80000001
- strComputer = "."
-
- Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
- strComputer & "\root\default:StdRegProv")
-
- strKeyPath = "Control Panel\Appearance\Schemes"
-
- ' ~~~ Enumerate the high contrast themes stored in the registry hive
- oReg.EnumValues HKEY_CURRENT_USER, strKeyPath, arrValueNames, arrValueTypes
-
- Select Case bCalledFrom
- Case "HTA"
- ' ~~~ Populate the enumerated themes in the dd list
- For iTheme = 0 To UBound(arrValueNames)
- Call PopulateContrast( arrValueNames(iTheme) )
- Next
- Case "WSF"
- ' ~~~ Return the actual theme name stored in the registry
- For iTheme = 0 To UBound(arrValueNames)
- If UCase( arrValueNames(iTheme) ) = UCase( sContrast ) Then
- GetContrastThemes = arrValueNames(iTheme)
- Exit For
- End If
- Next
- End Select
- End Function
-
- ' ~~~
- ' ~~~ private methods
- ' ~~~
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: Class_Initialize
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Used internally by the class when it is created.
- ' *** Declared as private because it must not be called directly.
- ' *** ------------------------------------------------------------------------------
- ' ***
- Private Sub Class_Initialize
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
-
- strAccessibility = chr(34) & GetRootFolder & "\bin\AccessibilityTool.exe" & chr(34)
- HKEY = "HKEY_CURRENT_USER\Software\Microsoft\"
- End Sub
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: Class_Terminate
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Used internally by the class when it is destroyed.
- ' *** Declared as private because it must not be called directly.
- ' *** ------------------------------------------------------------------------------
- ' ***
- Private Sub Class_Terminate
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
- End Sub
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: ShellRun(sCmd)
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Executes the AccessibilityTool.exe in the command line
- ' *** And returns 1 (success) and 0 (failure)
- ' *** ------------------------------------------------------------------------------
- ' ***
- Private Function ShellRun(sCmd)
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
-
- ShellRun = oShell.Run (sCmd,0,True)
- End Function
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: HideOSKeyWarning()
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Called to hide the warning window for os key
- ' *** ------------------------------------------------------------------------------
- ' ***
- Private Function HideOSKeyWarning()
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
-
- Dim strKeyPath, strValueName, bRegResult
- Dim strValue(503)
- Dim iKey,iUpper
- const HKEY_CURRENT_USER = &H80000001
-
- strKeyPath = "Software\Microsoft\Osk"
- strValueName = "Setting"
-
- bRegResult = oWmiReg.GetBinaryValue (HKEY_CURRENT_USER,strKeyPath,_
- strValueName,strValue)
-
- If bRegResult = 0 Then
- ' ~~~ If registry exists, change the last four values to hidewarning
- ReDim preserve strValue(uBound(strValue))
- iUpper = uBound(strValue)
- For iKey = iUpper-4 to iUpper
- strValue(iKey) = 0
- Next
-
- RegWrite "HKEY_CURRENT_USER" & "\" & strKeyPath & "\" & strValueName,strValue, "REG_BINARY"
-
- Else
-
- ' ~~~ Registry for OSK does not exists
- ' ~~~ Set the Binary value for the "Setting" reg value
- strValue = Array(4,0,0,0,0,0,0,0,0,0,0,0,192,192,192,0,255,128,192,0,0,255,64,0,128,128,255,0,2,0,0,0,_
- 1,0,0,0,101,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,232,3,0,0,245,255,255,255,0,0,0,0,_
- 0,0,0,0,0,0,0,0,188,2,0,0,0,0,0,0,3,2,1,34,77,83,32,83,104,101,108,108,32,68,108,103,_
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,_
- 152,58,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,2,0,0,0,1,0,0,0,7,0,0,0,7,0,0,0,_
- 16,0,0,0,7,0,0,0,0,0,0,0,0,0,0,0,188,2,0,0,0,0,0,0,1,2,2,34,83,121,115,116,101,109,0,16,104,138,247,12,_
- 172,0,1,0,148,51,2,0,0,0,87,1,0,0,9,0,139,1,164,1,0,0,0,0,128,255,128,0,1,0,0,0,_
- 32,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,184,0,0,0,206,0,0,0,31,2,0,0,_
- 50,3,0,0,226,2,0,0,109,1,0,0,238,2,0,0,57,2,0,0,0,0,0,0,0,0,0,0,114,0,0,0,177,0,0,0,0,0,188,66,_
- 0,0,200,65,113,0,0,0,114,0,0,0,115,0,0,0,116,0,0,0,117,0,0,0,118,0,0,0,119,0,0,0,_
- 120,0,0,0,121,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,_
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,_
- 0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,_
- 0,0,0,0,244,1,0,0,1,0,0,0,0,0,0,0)
-
- ' ~~~ Create two registry keys for OSK
- ' ~~~ Create the setting BINARY value
- RegWrite "HKCU\Software\Microsoft\Osk\Setting", 0, "REG_BINARY"
-
- ' ~~~ Write the setting key value
- RegWrite "HKCU" & "\" & strKeyPath & "\" & strValueName, strValue, "REG_BINARY"
-
- ' ~~~ Create the Stepping DWORD value
- RegWrite "HKCU\Software\Microsoft\Osk\Stepping", "3", "REG_DWORD"
-
-
- End If
-
- End Function
-
- End Class