Re: Getting logged in user from a service?
- From: "Willy Denoyette [MVP]" <willy.denoyette@xxxxxxxxxx>
- Date: Tue, 5 Jun 2007 17:13:54 +0200
"Larry Smith" <no_spam@xxxxxxxxxxx> wrote in message news:unH$%23m3pHHA.4388@xxxxxxxxxxxxxxxxxxxxxxx
The purpose of the Framework is to virtualize the underlying OS services and the HW, for instance by providing a layer in top of Win32, so you better stay away from calling Win32 API's through PInvoke if you can achieve the same (or better) when using the Framework classes.
That said, when the service restarts, you simply need to query whether the process is already running using the System.Diagnostics.Process class or the System.Management classes , get it's PID and pass it to something like the "GetOwner" (using WMI Win32_Process class) I posted in my previous reply.
He's dealing with Windows constructs here (services, WMI etc) which either have no (compatible) analogue outside the Windows world or whose support and/or availability is questionable (assuming he's even targetting such environments which is highly unlikely). Pedantic arguments about a virtual environment therefore don't apply IMO. Arguments about ease-of-use do apply however so on that we agree. P/Invoke is complicated and error-prone so should generally be avoided where possible. However, a service is inherently low-level and shouldn't be relying on .NET in the first place IMO. Even WMI is questionable here. While supported in .NET, a service should usually be light-weight with few dependencies. This is much better accomplished by relying on native OS functionality. Unfortunately, in the real world you require very experienced (and more expensive) C++/ WinAPI developers to write and support this. It's not viable in many shops and these types of developers are also becoming an endangered species (I'm one of them). Your points are therefore well taken.
Sorry, I'm afraid I have to disagree with your statement that a Service as being low-level and should not rely on .NET, why did MS add Windows Services support to the FCL if this was true? The days that authoring a Service was a privilege of C++ are over, however, I agree that not all services should be implementd using .NET, but the same goes for other kind of applications, I also agree, that as a result of .NET, way too many applications are now implemented as a Windows Services, but that's just another discussion.
Now , when I'm talking about "virtualization" I'm actually talking about hiding details like "Windows OS" flavors and versions, and this is what the CLR and the .NET Framework is all about. If you are coding directly against the OS services (that is, by directly calling WIN32 Api's) you have to consider a lot of things at "development" time, things like - is the API available on the *target* machine? - What are the security constraints, what privileges are there required to call these API when running as say "Local Service"? Can the API access a remote server instance? Most of these things are taken care of by the framework and it's underlying services, whatever these are, and in this particular case the underlying service is native WMI in top of Win32.
Even if you opt to use C++ to implement "low-level" Services, you should definitely consider WMI for most of it's "management" tasks, and this is exactly what most of the MS Services do these day's.
Willy.
.
- Follow-Ups:
- Re: Getting logged in user from a service?
- From: Larry Smith
- Re: Getting logged in user from a service?
- From: Ben Voigt [C++ MVP]
- Re: Getting logged in user from a service?
- References:
- Getting logged in user from a service?
- From: JamesB
- Re: Getting logged in user from a service?
- From: Nicholas Paldino [.NET/C# MVP]
- Re: Getting logged in user from a service?
- From: JamesB
- Re: Getting logged in user from a service?
- From: Willy Denoyette [MVP]
- Re: Getting logged in user from a service?
- From: JamesB
- Re: Getting logged in user from a service?
- From: Larry Smith
- Re: Getting logged in user from a service?
- From: Willy Denoyette [MVP]
- Re: Getting logged in user from a service?
- From: Larry Smith
- Getting logged in user from a service?
- Prev by Date: Re: C# HID and Vista 64
- Next by Date: Re: anonymous initializer problem
- Previous by thread: Re: Getting logged in user from a service?
- Next by thread: Re: Getting logged in user from a service?
- Index(es):
Relevant Pages
|
Loading