Solved

Problem with Windows Service Project

Posted on 2006-11-16
9
326 Views
Last Modified: 2008-02-01
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?
0
Comment
Question by:cityofcocoabeach
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 15

Expert Comment

by:ozymandias
ID: 17960897
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.
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 17961159
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......
http://www.experts-exchange.com/Operating_Systems/Q_21998064.html?query=osk&clearTAFilter=true
0
 
LVL 14

Expert Comment

by:existenz2
ID: 17961312
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.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:cityofcocoabeach
ID: 17967028
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?
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 17967161
>>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.

0
 

Author Comment

by:cityofcocoabeach
ID: 17967361
>>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.
0
 

Author Comment

by:cityofcocoabeach
ID: 17968309
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.  
0
 

Accepted Solution

by:
PashaMod earned 0 total points
ID: 18012828
Closed, 500 points refunded.
PashaMod
Community Support Moderator
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question