> If I log on to the remote desktop of the PC while the
> service is running I cannot log off. Nothing happens if I try.
Are you referring to accessing the PC via a remote connection, such as
PCAnywhere, iTivity, Terminal Services, etc?
> Where should I start looking here?
Have you looked at the NT Event Log yet?
Do you have an OnStop event handler assigned that ever sets the Stopped
parameter to false?
> my tests show that it is enough that the service has been started
> (no client connected) for the logoff/restart block to be there.
There has to be more happening than just that. What exactly did you do
during your tests? What code was implemented? What operations did you
perform, and in what order?
Gambit
If someone connects then the service will create a handler for the
client and pass it the socket variable over which all future
communications will happen. This has worked fine for several years.
Now something has happened that seems to be connected to my service:
If I log on to the remote desktop of the PC while the service is
running I cannot log off. Nothing happens if I try.
A Windows update install that required a reboot also failed when
trying.
If I stop my service then it is possible to log off/restart.
If I then log on I can immediately log off, but if I log on and then
start the service it blocks the logoff again.
Where should I start looking here?
The main service app does nothing else than listens on the socket
until a client connects and my tests show that it is enough that the
service has been started (no client connected) for the logoff/restart
block to be there.
I have not touched the main service in a long time, the only
development I have done is in the objects that will be created once
the client connects, so these are not even created at the time the
block appears...
Is there some kind of CloseQuery that a service app receives that I
can implement and handle? I need at least to try and log what happens
when Windows tries to log off (it should really not communicate with
the service at this time, the whole idea with a service is that it is
logon independent).
Any hints welcome!
/BoB
>
>"Bo Berglund" <bo.be...@telia.com> wrote in message
>news:g2ngt39lkqk6flgaf...@4ax.com...
>
>> If I log on to the remote desktop of the PC while the
>> service is running I cannot log off. Nothing happens if I try.
>
>Are you referring to accessing the PC via a remote connection, such as
>PCAnywhere, iTivity, Terminal Services, etc?
I myself is logging on to the XP-Pro SP2 box via Remote Desktop after
establishing a VPN connection to the LAN the PC lives on (some 6000
miles away).
But I have a techie on site who has tested the exact same thing
directly on the PC console. The behaviour is the same...
>> Where should I start looking here?
>
>Have you looked at the NT Event Log yet?
Yes, there is nothing mentioned there that I can relate to the
difficulty of logging off the PC.
>
>Do you have an OnStop event handler assigned that ever sets the Stopped
>parameter to false?
I assume you mean the ServiceStop event handler?
Yes I have one that first closes the server socket then sets Stopped
:= true.
However, this is not called when I try to log off the PC (and it
should not because the service should continue running). There is
nothing in my logfile...
>> my tests show that it is enough that the service has been started
>> (no client connected) for the logoff/restart block to be there.
>
>There has to be more happening than just that. What exactly did you do
>during your tests? What code was implemented? What operations did you
>perform, and in what order?
My test is very simple:
1) Log on to the XP desktop
2) Try to log off again. Fails if the service is running.
3) Stop service
4) Try to log off from the desktop. Now it succeeds
5) Log in again
6) Log off - success because service is not running
7) Log in again
8) Start service
9) Try to log off - fails
10) Stop service
11) Try to log off - succeeds
No code was involved in this at all, I simply started or stopped the
service, which has been working well since 2005.
---- UPDATE ----
While writing this reply I tried two things:
1) Retrieved an older version of the server from CVS and tried it,
same result!
2) Realized that when I debugged another problem that occurred when
the server tried to start a GUI program when noone was logged on, I
actually chaged the service settings.
What I did was to check the "Allow service to interact with desktop"
for the service. It did not affect the bug I was looking for (see
other thread) but was left there.
Now I logged back on and changed the setting (unchecked the box) and
restarted the service.
Now logging off actually works!
So the cause of the problem was that the service running under the
LOCAL SYSTEM account was allowed to interact with the desktop and this
blocked any logged on user from actually being able to log off!
Strange, but now solved :-)
/BoB
Thanks for the interesting analysis & solution. I'm sure this will become a
Google groups search fave. :)
--
Ray Marron
I've been running plenty of services in my live as LocalSystem and
interaction with desktop enabled w/o any problem of that kind in the past.
That simply cannot be the reason (get and try my NT Wrapper from
http://www.duodata.de/ntwrapper/ and start i.e. notepad.exe as an
interactive service (doesn't work in Vista any more, of course).
--
Arno Garrels
>>Have you looked at the NT Event Log yet?
>
> Yes, there is nothing mentioned there that I can relate to the
> difficulty of logging off the PC.
So, if you open the log and then attempt a logoff, no new event messages
appear in any of the log sections?
> I assume you mean the ServiceStop event handler?
Yes.
> No code was involved in this at all, I simply started or stopped
> the service, which has been working well since 2005.
Have you tried creating a new blank service project instead of using your
live project for testing?
> Realized that when I debugged another problem that occurred
> when the server tried to start a GUI program when noone was
> logged on, I actually chaged the service settings.
Services should not be doing anything UI-related at all. Move the UI logic
into a separate non-service app that runs only when the user is logged on,
and which communicates with the service. The service can then ask the app
to display whatever UI is needed, or spawn UI processes, etc.
If the service must start a UI process, then at least detect whether a user
is logged in and then use CreateProcessAsUser() instead of just the plain
CreateProcess().
> What I did was to check the "Allow service to interact with desktop"
> for the service. It did not affect the bug I was looking for (see
> other thread) but was left there.
You really should not enable that feature. In fact, it is no longer allowed
in Vista. Always leave is unchecked.
Gambit