Monday, 8 February 2010

[Fix] Keyboard not working on Windows login screen

0 comments
Apple KeyboardI had an issue with my main development machine at work last week. It was booting up fine but as soon as it got to the Windows XP login screen the keyboard froze up. I could still move the move and the computer was still responsive.

I did a bit of troubleshooting and found that the keyboard worked correctly in the BIOS and also worked fine in a Linux Live CD. I could even remote desktop onto the machine and it the keyboard worked correctly. I tried a few different keyboards and the computer did the same. So I thought it was a driver issue...

To fix it I tried to do a check disk (chkdsk /r) from the recovery console on Windows XP installation CD. This is done by running the Windows XP installation CD, choosing Repair Console (option 'r') from the first option screen and then typing 'chkdsk /r' when the console loads.

Check disk took about 1 - 2 hours to complete and showed that it had fixed some errors. So I exited the console and rebooted the machine however the problem remained.

Finally I found a post by Ryan. T. Adams called Keyboard Not Working Due to Missing Or Corrupt Drivers (Code 39). This had a step by step guide of how to fix the problem.

Below are the steps I followed to fix the problem. Please note this method requires editing the registery so make a backup of the registry and be careful.


  1. Go to your Start menu and click “Run…”
  2. In the Run box that opens, type “regedit” and press Enter.
  3. In the new window that opens, click the “Edit” menu, then “Find.”
  4. In the find filed, type “kbdclass” and press enter.
  5. The registry editor will now search for any key that has “kbdclass” in it. What you are looking for is any that have a name of “UpperFilters” and a data of ” something_random_here kbdclass” You may need to go to “Edit,” “Find Next” if the search finds something else first.
  6. Once you find the key, double click on it, and edit the text so that it includes only “kbdclass”. Press OK.
  7. Continue searching (using the “Edit” and “Find Next” menu) until you have found and edited all of the “UpperFilters” keys. Again, all should have a data filed that includes only “kbdclass”.
  8. Close the registry editor.
  9. Go to the device manager, find your keyboard in the list (which should still be reporting a “Code 39″ error), and uninstall it.
  10. You should then restart your computer, and with any luck, your keyboard will work upon rebooting.


Thanks to Ryan for this great fix

Wednesday, 27 January 2010

My Thinstation Configuration

0 comments
I have been asked for our thinstation configuration file a few times so here it is. I will try to explain the customisations we have done in the comments

# --- Network configuration

# Give a different name to each PC
# NET_HOSTNAME=MyThinclient

# We are using a cd based system so we don't use tftp server for config
NET_FILE_ENABLED=Off

# If you want to use a DHCP server, comment out these params:
#NET_USE_DHCP=Off
#NET_IP_ADDRESS=192.168.0.70
#NET_MASK=255.255.255.0
#NET_GATEWAY=192.168.0.1
#NET_DNS1=192.168.0.1
#NET_DNS2=192.168.0.21
#NET_DNS_SEARCH=cartoons.org.nz

# --- Session Options
#
# Note: # is a number equal to or greater than 0
#
# SESSION_#_TITLE Title description for SESSION. Needed for replimenu.
# SESSION_#_TYPE Package type, choose beetwen:
# - vncviewer Start vncviewer in X
# - rdesktop Start rdesktop in X
# - x Start x-terminal session (xdm)
# - ssh Start ssh client in linux console
# - telnet Start telnet client in linux console
# - ica Start Citrix ICA client in X
# - tn5250 Start AS400 client in linux console
# SESSION_#_SCREEN Display number to run the X server on
# SESSION_#_AUTOSTART ON Application will be executed immediately at startup
# OFF Application will appear in a menu to be started manually
# SESSION_#_WORKSPACE Workspace to run program on in a window manager
# SESSION_#_type_SERVER IP address/hostname of the server
# SESSION_#_type_OPTIONS Command line options for the session type


# Individual Session Settings, override defaults
#
# IMPORTANT: Make sure you minimum have a SESSION_0. Otherwise you will get an error
# on boot. You may have additional sessions: SESSION_1, SESSION_2 ...
# SESSION_0 is on ctrl-alt-F3
# SESSION_1 is on ctrl-alt-F4
# ... etc.


# If you only have one session, it is a good idea to uncomment this line:
AUTOSTART=On

# Typical Windows 2000 session
#SESSION_0_TITLE="Windows 2000 terminal server"
#SESSION_0_TYPE=rdesktop
#SESSION_0_RDESKTOP_SERVER=192.168.1.1
#SESSION_0_RDESKTOP_OPTIONS="-u 'fred'"

#SESSION_0_TITLE="NewCitrixServer"
#SESSION_0_TYPE=ica
#SESSION_0_ICA_SERVER=xxx.xxx.org.uk

# Important: don't insert spaces in the session title
# ica.xxx.org.uk is a dns round robin address for all citrix servers in farm
SESSION_0_TITLE="CitrixServerAppDesktop"
SESSION_0_TYPE=ica
SESSION_0_ICA_APPLICATION_SET="Desktop"
SESSION_0_ICA_SERVER=ica.xxx.org.uk

# Typical Windows 2003 Server session, with True-color and sound redirection
# Note: use '-a 16' and '-a 24' to get true-color with Windows 2003+
# Older servers don't support these color depths, wrong settings may cause connection to fail.
#SESSION_1_TITLE="Windows 2003 terminal server (16 bit color depth)"
#SESSION_1_TYPE=rdesktop
#SESSION_1_RDESKTOP_SERVER=192.168.1.1
#SESSION_1_RDESKTOP_OPTIONS="-u user -p password -a 16 –r sound"
#Example on USB Printer Redirection for Rdesktop
#SESSION_#_RDESKTOP_OPTIONS="-r printer:usb='DYMO LabelWriter 400 Turbo'"

# Important: don't insert spaces in the session title
#SESSION_0_TITLE="CitrixServer"
#SESSION_0_TYPE=ica
#SESSION_0_ICA_APPLICATION_SET="Microsoft Word"
#SESSION_0_ICA_OPTIONS="-username donald -password qwak"

# ICA: Instead of connecting to an "application set",
# you can directly connect to a specific server desktop
# Important: don't insert spaces in the session title
#SESSION_3_TITLE="CitrixServer"
#SESSION_3_TYPE=ica
#SESSION_3_ICA_SERVER=ICA

#SESSION_#_TITLE="Unix server"
#SESSION_#_TYPE=x
#SESSION_#_X_SERVER=192.168.1.2
# Default is '-query'
##SESSION_#_X_OPTIONS="-indirect"
# You should set also "SCREEN_X_FONT_SERVER", below

#SESSION_#_TITLE="VNC server"
#SESSION_#_TYPE=vncviewer
#SESSION_#_VNCVIEWER_SERVER=192.168.1.2

#SESSION_#_TITLE="Telnet server"
#SESSION_#_TYPE=telnet
#SESSION_#_TELNET_SERVER=192.168.1.2

#SESSION_#_TITLE="SSH server"
#SESSION_#_TYPE=ssh
#SESSION_#_SSH_SERVER=192.168.1.2

#SESSION_#_TITLE="AS400 server"
#SESSION_#_TYPE=tn5250
#SESSION_#_TN5250_SERVER=192.168.1.2
# Use this option to specify keyboard map
#SESSION_#_TN5250_OPTIONS="map=280"
# Other options
#SESSION_#_TN5250_OPTIONS="env.DEVNAME=JDevBox1 +underscores env.TERM=IBM-3477-FC"


# --- General Options
#
# AUDIO_LEVEL Audio Level for sound, 0-100
# KEYBOARD_MAP Keyboard layout
# TIME_ZONE Used to set time zone on TS client by entering the UTC offset.
# This can be set automatically if the appropriate dhcpc option is selected
# (Option 2, time offset in seconds)
# RECONNECT_PROMPT This displays the reconnection/shutdown options for when a session is ended
#
# OFF No reconnect prompt
# ON Reconnect prompt will be displayed
# MENU Shows a menu with a shutdown and reconnection option
# MENUXX As MENU option, but the XX is a time period in minutes.
# After XX minutes shutdown will occur unless the reconnect option
# is choosen

AUDIO_LEVEL=67

# Look inside BuildFiles\build.conf* file for a list of the supported KB layouts
# important to change the keyboard map / timezone to your local settings else time is wrong in the session. Reconnect set to "Shutdown or Reconnect"
KEYBOARD_MAP=en_gb
#TIME_ZONE="UTC-00:00"
TIME_ZONE="GMT+0BST,M3.5.0,M10.5.0"
RECONNECT_PROMPT=MENU01


# --- X Server Options
#
# SCREEN_RESOLUTION Screen resolutions available in the workstations
# SCREEN_COLOR_DEPTH Number of bits per pixel (8,16,24)
# SCREEN_HORIZSYNC Monitor horizontal sync frequency in Khz.
# If left blank Xorg will try to detect with DDC
# SCREEN_VERTREFRESH Monitor vertical refresh frecuency in Hz.
# If left blank Xorg will try to detect with DDC
# SCREEN_X_FONT_SERVER IP address or hostname of the font server for X
#
# Screen Saver Settings
# SCREEN_BLANK_TIME Minutes to X session goes blank
# SCREEN_STANDBY_TIME Minutes to X session goes into standby mode
# SCREEN_SUSPEND_TIME Minutes to X session goes into suspend mode
# SCREEN_OFF_TIME Minutes to X session turn off
#
# MOUSE_PROTOCOL Mouse protocol type (Microsoft, PS/2, etc.)
# (mouse is autodetected, use this only if it fails)
# MOUSE_DEVICE Mouse device: /dev/ttyS0 -> COM1
# /dev/ttyS1 -> COM2
# /dev/ttyS2 -> COM3
# /dev/ttyS3 -> COM4
# /dev/psaux -> PS/2 mouse port
# /dev/input/mice -> USB mouse (needs USB package)
# MOUSE_RESOLUTION Mouse resolution
# MOUSE_ACCELERATION Mouse acceleration
# X_NUMLOCK Set numlock state on boot
# X_COOKIE Will set X Cookie if specified

#SCREEN_RESOLUTION="800x600"
SCREEN_RESOLUTION="1024x768"

SCREEN_COLOR_DEPTH="24"

#SCREEN_HORIZSYNC="30-64"
#SCREEN_VERTREFRESH="56-87"

#SCREEN_X_FONT_SERVER=192.168.1.2:7100

SCREEN_BLANK_TIME=10
SCREEN_STANDBY_TIME=20
SCREEN_SUSPEND_TIME=30
SCREEN_OFF_TIME=60

# Mouse acceleration: We found in testing that the speed of the cursor was much slower that fat clients so we added following options to try and speed it up.

#MOUSE_PROTOCOL=PS/2
MOUSE_PROTOCOL=IMPS/2
#MOUSE_DEVICE=/dev/psaux
#MOUSE_RESOLUTION=100
#X_NUMLOCK=Off
MOUSE_ACCELERATION=1/8
#X_COOKIE=36d71ab65c10ef065702c111a3d31593


# --- Citrix ICA Specific Options
#
# GLOBAL Settings
#ICA_USE_SERVER_KEYBOARD Use default server keyboard, otherwise use KEYBOARD_MAP
# variable
#ICA_BROWSER_PROTOCOL Broswer protocol, can be HTTPonTCP or UDP
#
# APPLICATION SET settings
#ICA_ENCRYPTION Encryption level for ICA
# Valid Settings Below
# "Basic"
# "RC5 (128 bit - Login Only)"
# "RC5 (40 bit)"
# "RC5 (128 bit)"
# "RC5 (56 bit)"
#ICA_COMPRESS Compression, On/Off
#ICA_AUDIO Audio, On/Off
#ICA_AUDIO_QUALITY Audio Quality, Low, Medium, High
#ICA_PRINTER This will turn on ICA autocreate printers, see printer section
# for details, On/Off
#
# NOTE: You must have the lpr package included for this option
# to work.
#
#ICA_APPLICATION_SET Published Application (Not needed if using
# ICA_SERVER)
#ICA_SERVER Server to Connect to (Not needed if using
# ICA_APPLICATION_SET, but needed if the ICA-Masterbrowser
# is not on the local network.)
#ICA_WFCLIENT_type_specific This allows you to specify specific config file details for global ica
# parameters any parameter can be changed with this setting. An example of this is
# ICA_WFCLIENT_CLIENTDRIVE="On"
# See your application manual for documentation on the settings which
# can be used.

#ICA_USE_SERVER_KEYBOARD=Off
ICA_BROWSER_PROTOCOL=HTTPonTCP
#ICA_SERVER=
#ICA_ENCRYPTION=Basic
#ICA_COMPRESS=On
#ICA_AUDIO=On
#ICA_AUDIO_QUALITY=Low
#ICA_PRINTER=off
#ICA_SEAMLESS_WINDOW=Off


# --- LP Server Printing Options
#
# PRINTER_0_NAME Workstation Printer Name, Can be Any Valid Name
# If you have turned ICA_PRINTER=ON then this is the
# name of the printer driver
# PRINTER_0_DEVICE Workstation printer device (if not specified devices
# are not loaded).
# /dev/printers/[0-2] for parallel ports
# /dev/ttyS[0-3] for serial ports
# /dev/usb/lp[0-2] for USB printers
#
# PRINTER_0_TYPE P for parallel, S for serial, U for USB printer
# PRINTER_0_OPTIONS Serial port options.
# PRINTER_1_* See PRINTER_0_*
# PRINTER_2_* See PRINTER_0_*
# PRINTER_3_* See PRINTER_0_*

#PRINTER_0_NAME="parallel"
#PRINTER_0_DEVICE=/dev/printers/0126
#PRINTER_0_TYPE=P

#PRINTER_1_NAME="serial"
#PRINTER_1_DEVICE=/dev/ttyS1
#PRINTER_1_TYPE=S
#PRINTER_1_OPTIONS="speed 38400 -imaxbel"

#PRINTER_2_NAME="usb"
#PRINTER_2_DEVICE=/dev/usb/lp0
#PRINTER_2_TYPE=U


#ICA Autocreate Printer Example
# Local printers can be a bit hit and miss (better with parallel printers).
# Must give thinstation computer a static ip address on dhcp server then
# install printer on print server with static ip address and correct drivers
# and finally change the port in printer settings from
# 9100 to 9101 ONLY IF printer is usb.
PRINTER_0_NAME="parallel"
PRINTER_0_DEVICE=/dev/printers/0
PRINTER_0_TYPE=P

PRINTER_1_NAME="usb"
PRINTER_1_DEVICE=/dev/usb/lp0
PRINTER_1_TYPE=U



Thinstations configuration can be a bit daunting initially but once you get the hang of it, it mostly makes sense.

Please send me your comments or questions.

Tuesday, 8 December 2009

[Code] Delphi Copying To and From TRichEdit

0 comments
At work we have been looking at providing basic text editor facilities to some of our users.
After looking for some third party components we decided to use the built in Win32 palette TRichEdit component instead.

Below is the code we used to insert Rich Text Format text from a database blob field into a TRichEdit component.

try
MS := TMemoryStream.Create; try TBlobField(CdsXXXReason).SaveToStream(MS);
MS.Position := 0;
RichXXX.Lines.LoadFromStream(MS);
finally
FreeAndNil(MS);
end;
And then the code to save Rich Text Format text from a TrichEdit component to a database blob field
MS := TMemoryStream.Create();
try
CdsLabComment.Edit;
RichLabComment.Lines.SaveToStream(MS);
MS.Position := 0;
CdsXXXReason.LoadFromStream(MS);
CdsXXX.Post;
CdsXXX.ApplyUpdates(0);
finally
FreeAndNil(MS);
end;
Finally we needed to send the Rich Text Format text from the database to a word document.
MS := TMemoryStream.Create;
SlRichXXX := TStringList.Create;
try
TBlobField(CdsXXXReason).SaveToStream(MS);
MS.Position := 0;
SlRichComment.LoadFromStream(MS);
StrXXX := SlRichXXX.GetText;
RTFtoClipboard( StrXXX, StrXXX);
AppWord.Selection.Paste;
finally
MS.Free;
SlRichXXX.Free;
end;
Below is the required RTFtoClipboard procedure.
procedure RTFtoClipboard(txt: string; rtf: string);
var
Data: Cardinal;
CF_RTF : Word;
begin
CF_RTF := 0;
with Clipboard do
begin
CF_RTF := RegisterClipboardFormat('Rich Text Format');
Data := GlobalAlloc(GHND or GMEM_SHARE, Length(rtf)*SizeOf(Char) + 1);
if Data <> 0 then
try
StrPCopy(GlobalLock(Data), rtf);
GlobalUnlock(Data);
Open;
try
AsText := txt;
SetAsHandle(CF_RTF, Data);
finally
Close;
end;
except
GlobalFree(Data);
end;
end;

Hope this helps someone

Monday, 30 November 2009

[Tip] Remove Password from Office 2003 document

0 comments
At work we needed to get into change a password protected word document of which everyone had forgotten the password. To do this my colleague found a great tip for removing passwords.

Here it is

1) With the document open press F11 while holding down shift and alt (Alt-Shift-F11). This should launch the script editor in Word.

2) Next select the find option (or hit ctl-f), and run a find for the word "password." This should highlight something like this "32943208".

3) Delete the letters and numbers between the tags (in the above example this would be the 32943208).

4) Save the document in the script editor and close the window. You should now be back in your Word document.

5) From the "Tools" pull down menu, select "unprotect." Your document should now be unprotected.

This should work the same way for Microsoft Excel.

Great tip thanks to Ashley Kozaczek.

Saturday, 14 November 2009

Sql Server 2008 Database Mirroring - Cannot Create Endpoint

0 comments
We have been testing SQL Server 2008 for a while now. This weekend was the date set to move our main database to SQL Server 2008 and also create a mirror on original SQL Server. We did a side by side install of SQL Server 2008 on the original server, which had SQL server 2005 on it.

The move to SQL Server 2008 went fine. I did a database copy form SQL 2005 to SQL 2008 on both the principal and the mirror instances. I then made a backup of the database from the principal instance and restored it to the mirror in recovery mode. Then I did a log backup on the principal server and restored it to the mirror database and still left it in recovery mode.

Finally it came to setting up the mirror. I used the wizard and got all the way through. Between it cam to starting the mirror an error showed up stating that the end point on the original server couldn't be contacted.

Firstly I thought that there was a firewall issue. However on checking I found that Windows firewall was switched off on both server.

Then I realised the issue was to do with the fact that mirroring had originally been enabled on the mirror servers SQL 2005 instance. I had gone through all mirrored databases on SQL 2005 instance and removed all mirroring but some where SQL 2005 was still keeping hold of the default 5022 endpoint.

After a bit of Googling and "Books On Line (ing)" I found two SQL statements that showed the problem when ran on the master database.


SELECT *
FROM sys.tcp_endpoints t

SELECT *
FROM sys.database_mirroring_endpoints e


The two statements show mirroring endpoints for an instance.

I had to delete the lines related to mirroring on the SQL Server 2005 instance. Once this was done I was able to successfully start mirroring on SQL Server 2008 instance for our databases.

As with anything like this it is advisable to take a backup of your system before manually changing the master database