Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: OpenDesktop in a Windows service fails, GetLastError returns 183

200 views
Skip to first unread message
Message has been deleted

Sebastian G.

unread,
Mar 12, 2008, 10:19:33 AM3/12/08
to
jvs...@gmail.com wrote:

> I've written a Windows service in C#


in clear violation of Microsoft's recommendation ..


> _hDesktop = OpenDesktop("Default", 0, false,
> MAXIMUM_ALLOWED);


Shouldn't this be "WinSta0\\Default"?

jvs...@gmail.com

unread,
Mar 13, 2008, 1:39:31 AM3/13/08
to
On Mar 12, 11:19 pm, "Sebastian G." <se...@seppig.de> wrote:

No. Not according to the API documentation.

Regardless, I got the function to call properly. I had a messed up
prototype; once I fixed that, there were no more errors. It's a moot
point because I have since learned that global hooks *are not
possible* in Windows services regardless of the service process'
desktop. I'd have to use GetAsyncKeyState (which also isn't guaranteed
to work) but that would require more CPU usage. I'd have to turn on
logon/logoff auditing and watch the security event log just to detect
when as user as logged on or off and that's a bit too much overhead.
I'm shifting the paradigm to a user application or a driver.

So where does Microsoft say it's a bad idea to write services in C#?

Sten Westerback (MVP SDK 2005-6 :)

unread,
Apr 1, 2008, 8:18:14 AM4/1/08
to
>
><jvs...@gmail.com> wrote in message
>news:9b0873ac-adba-4eff...@s19g2000prg.googlegroups.com...

>On Mar 12, 11:19 pm, "Sebastian G." <se...@seppig.de> wrote:
>> jvst...@gmail.com wrote:
>> > I've written a Windows service in C#
>>
>> in clear violation of Microsoft's recommendation ..
>>
>> > _hDesktop = OpenDesktop("Default", 0, false,
>> > MAXIMUM_ALLOWED);
>>
>> Shouldn't this be "WinSta0\\Default"?
>
>No. Not according to the API documentation.
>
>Regardless, I got the function to call properly. I had a messed up
>prototype; once I fixed that, there were no more errors. It's a moot
>point because I have since learned that global hooks *are not
>possible* in Windows services regardless of the service process'
>desktop. I'd have to use GetAsyncKeyState (which also isn't guaranteed
>to work) but that would require more CPU usage. I'd have to turn on
>logon/logoff auditing and watch the security event log just to detect
>when as user as logged on or off and that's a bit too much overhead.

I would use RegNotifyChangeKeyValue on HKEY_USERS to wait for changes...

>I'm shifting the paradigm to a user application or a driver.

At the same time you should ensure your laws allow such monitoring...

>So where does Microsoft say it's a bad idea to write services in C#?

I don't think they say it directly.. but services are supposed to be
optimized and efficient... ;)

- Sten


Sebastian G.

unread,
Apr 1, 2008, 9:09:23 AM4/1/08
to
Sten Westerback (MVP SDK 2005-6 :) wrote:


>> So where does Microsoft say it's a bad idea to write services in C#?
> I don't think they say it directly.. but services are supposed to be
> optimized and efficient... ;)


AFAIR a Microsoft professional really said it directly. Read it somewhere at
Technet or blogs.msdn.com. Basically, the CLR is not supposed to fit into
the tight security requirements of a system service.

Scott Seligman

unread,
Apr 1, 2008, 11:33:30 AM4/1/08
to

Then they should stop shipping a CLR Service (Windows Mobile
Device Center) =)

--
--------- Scott Seligman <scott at <firstname> and michelle dot net> ---------
Better to light a candle than to curse the darkness.
-- Chinese Proverb

0 new messages