Re: Getting logged in user from a service?



"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.






.



Relevant Pages

  • RE: WMI for Windows XP
    ... how can I get WMI ... working on problematic Windows XP machines? ... The WMI component is a default component of the Windows XP system, ... Microsoft Online Community Support ...
    (microsoft.public.dotnet.general)
  • RE: BizTalk WMI performance issue
    ... If the servers are Windows 2003 SP1 or earlier, ... a look at the following WMI patches included in Windows 2003 SP2. ... WMI service on a Windows XP SP2-based computer or a Windows Server 2003 ... Microsoft Online Community Support ...
    (microsoft.public.biztalk.server)
  • Re: WMI and Win98?
    ... The first step for WMI support is to install the WMI core for Windows 98. ... Windows 98 machine across the network as the WBEM service (WMI's server ...
    (microsoft.public.win32.programmer.wmi)
  • Help - How to programmatically set up local printer share ?
    ... I am able to set up a local printer share using wmi under windows xp ... wmi which do support them. ... all of them while using getprinter/setprinter for w95/w98 use the old ...
    (microsoft.public.win32.programmer.networks)
  • Re: Getting logged in user from a service?
    ... better stay away from calling Win32 API's through PInvoke if you can ... low-level and shouldn't be relying on .NET in the first place IMO. ... require very experienced C++/ WinAPI developers to ... write and support this. ...
    (microsoft.public.dotnet.languages.csharp)

Loading