Link to home
Start Free TrialLog in
Avatar of cityofcocoabeach
cityofcocoabeach

asked on

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?
Avatar of ozymandias
ozymandias
Flag of United Kingdom of Great Britain and Northern Ireland image

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
http://www.microsoft.com/enable/training/windows2000/startkeyboard.aspx

Also, check out the accepted answer here......
https://www.experts-exchange.com/questions/21998064/Displaying-the-On-screen-keyboard-at-the-login-prompt.html?query=osk&clearTAFilter=true
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.
Avatar of cityofcocoabeach
cityofcocoabeach

ASKER

Thank you both for responding.

Ozymandias,
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.

>>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.
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.  
ASKER CERTIFIED SOLUTION
Avatar of PashaMod
PashaMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial