M
mwebb
At the request of my boss I have trying to run a script that will keep the
Num Lock on in XP. The idea is to set the registry key so that no matter what
the Num Lock is when the user logs off it will always be on at logon.
The script (below) is run as a logoff script that sets the value for Num
Lock on when the user logs off. The script runs fine and places the number in
the correct place in the registry but when the logon happens the Num Lock key
is off if the user had the key off when logging off before the script runs.
What is really frusturating is that the Num Lock key value is "on" after
logon but the actual key is off.
I am running the script to run synchronisly.
Apparently XP is reading the Num Lock key after the logoff script is run.
Running the script as logon script does not work either.
How can I get this script to work so the Num Lock is always on no matter
what the Num Lock setting is on logoff.
--------------------------------
'This logoff script uses WMI to determine the OS. If the OS is other than
WinXP the script quits.
'If the OS is WinXP the shell object is used to place a 2 in the registry so
at the next logon the
'Num Lock key is on.
Dim strComputer
Dim objWMIService
Dim colItems
Dim objItem
Dim strOS
Dim intOSType
Dim strOSSearch
Dim intRegVal
strComputer = "."
'Determine OS
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_OperatingSystem"
, , 48)
For Each objItem in colItems
strOS = objItem.Name
Next
'WScript.Echo strOS
strOSSearch = "XP"
intOSType = InStr(strOS,strOSSearch)
'If OS is not XP quit. If not check registry key
If intOSType = 0 Then
WScript.Quit
'If keyboard indicator is 2 quit. If not place "2" in the key
Else
Set WshShell = CreateObject("Wscript.Shell")
intRegVal = WshShell.RegRead("HKEY_USERS\.DEFAULT\Control
Panel\Keyboard\InitialKeyBoardIndicators")
WScript.Echo "Initial RegVal: " & intRegVal
If intRegVal <> 2 Then
WshShell.RegWrite"HKEY_USERS\.DEFAULT\Control
Panel\Keyboard\InitialKeyBoardIndicators" , 2, "REG_SZ"
End If
End If
intRegVal = WshShell.RegRead("HKEY_USERS\.DEFAULT\Control
Panel\Keyboard\InitialKeyBoardIndicators")
WScript.Echo "Final RegVal: " & intRegVal
WScript.Quit
Num Lock on in XP. The idea is to set the registry key so that no matter what
the Num Lock is when the user logs off it will always be on at logon.
The script (below) is run as a logoff script that sets the value for Num
Lock on when the user logs off. The script runs fine and places the number in
the correct place in the registry but when the logon happens the Num Lock key
is off if the user had the key off when logging off before the script runs.
What is really frusturating is that the Num Lock key value is "on" after
logon but the actual key is off.
I am running the script to run synchronisly.
Apparently XP is reading the Num Lock key after the logoff script is run.
Running the script as logon script does not work either.
How can I get this script to work so the Num Lock is always on no matter
what the Num Lock setting is on logoff.
--------------------------------
'This logoff script uses WMI to determine the OS. If the OS is other than
WinXP the script quits.
'If the OS is WinXP the shell object is used to place a 2 in the registry so
at the next logon the
'Num Lock key is on.
Dim strComputer
Dim objWMIService
Dim colItems
Dim objItem
Dim strOS
Dim intOSType
Dim strOSSearch
Dim intRegVal
strComputer = "."
'Determine OS
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_OperatingSystem"
, , 48)
For Each objItem in colItems
strOS = objItem.Name
Next
'WScript.Echo strOS
strOSSearch = "XP"
intOSType = InStr(strOS,strOSSearch)
'If OS is not XP quit. If not check registry key
If intOSType = 0 Then
WScript.Quit
'If keyboard indicator is 2 quit. If not place "2" in the key
Else
Set WshShell = CreateObject("Wscript.Shell")
intRegVal = WshShell.RegRead("HKEY_USERS\.DEFAULT\Control
Panel\Keyboard\InitialKeyBoardIndicators")
WScript.Echo "Initial RegVal: " & intRegVal
If intRegVal <> 2 Then
WshShell.RegWrite"HKEY_USERS\.DEFAULT\Control
Panel\Keyboard\InitialKeyBoardIndicators" , 2, "REG_SZ"
End If
End If
intRegVal = WshShell.RegRead("HKEY_USERS\.DEFAULT\Control
Panel\Keyboard\InitialKeyBoardIndicators")
WScript.Echo "Final RegVal: " & intRegVal
WScript.Quit