Problem with Windows Service Project

I’ve created a C# Windows Service project whose service main function instantiates a class library that spawns a new thread to create a new process with which to launch osk.exe (the Windows on-screen keyboard).  The purpose for creating this service is to have the on-screen keyboard appear immediately after startup (before the login screen) on a system that will have no keyboard hardware.

I had first built a test program (C# console application) to call the class library and test its functionality and it worked fine.  Then I created the Service Project including its installer classes and installed the service with installutil.  [Incidentally, all three projects—the class library that launches the osk in a new thread, the test console application, and the windows service—are in the same solution.]

Each time I manually start the service (using the MMC snap-in) I get the following message:
" The service <name> on Local Computer started and then stopped.  Some services stop automatically if they have no work to do…"

Strange... The class library contains the necessary start and stop methods, and I copied the same code from the test program to the OnStart () method of the service class. Can anyone help?
Who is Participating?
PashaModConnect With a Mentor Commented:
Closed, 500 points refunded.
Community Support Moderator
I don't think you can do this.

You can create a service from any executable using the sc command :

sc create OnScreenKeyboard binpath= c:\windows\system32\osk.exe

This will create a service based on the on screen keyboard.
You can then go into the service control snap-in and set it to interact with the desktop, start automatically etc
However, even when you start the service its status never gets passed starting, even theough the keyboard appears and eventually it will just quit.
If all you ned to do is display the osk at logon/startup there are two methods detailed here :

Starting On-Screen Keyboard Automatically When Windows Starts

Also, check out the accepted answer here......
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

The Windows Service needs to have the appriorate rights to execute the osk.exe. Most likely it doesnt have them. If it tries to runs under the User account you also need to be logged in to get it to work.
cityofcocoabeachAuthor Commented:
Thank you both for responding.

The first link doesn't work for us since the Option described doesn't exist on Windows XP.
Also, we had tried the steps mentioned in the other link, but it's not working for us.  I can successfully get the osk to appear before the log-in but after logging in using the osk, the osk is no longer visible although a look at the running processes shows it running under the system account.  I can only get it to appear by typing CTRL+ALT+DEL with an external keyboard. ?!?
Even so, it goes away when logging off, so I'm forced to use an external keyboard to log in after which it reappears but this time running under my user account.

This is the reason I'm attempting to create a proper service application that will startup and persist unlike with the sc.exe option.
I've succeeded in getting the service (that launches the osk) to start and stop successfully, but the osk still shuts down when logging off.  A post in another forum suggested the application may be displaying on the wrong WinStation, but I'm not sure what this is about.  Any ideas?
>>The first link doesn't work for us since the Option described doesn't exist on Windows XP.
Yes it does...or at least it does in my windows xp.
If you have a "windows" key on your keyboard (the one with the little windows flag) hold it and "u" down togetehr and you will get the dialog up that allows you to set that option.

No other ideas at present I'm afraid, unless you write your own osk program that behaves properly and doesn't shut down all the time.

cityofcocoabeachAuthor Commented:
>>Yes it does...or at least it does in my windows xp.

The only options I have are:
Start automatically when I log in
Start automatically when I lock my desktop
Start automatically when Utility Manager starts

All of these require some keyboard strokes before the osk appears.
Thanks anyway.
cityofcocoabeachAuthor Commented:
Found a solution…

It appears the process of logging off kills any non-service type processes, even though it was spawned by a service which is still running.  Now I’m having the service poll the running process at regular intervals to see if the osk was exited by other than the service itself, and if so restart it.  
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.