We created a Windows service that runs on client computers, which downloads a newer version from time to time, and then performs a self-update: installs a new service, starts it, stops the old one and ultimately deletes it, the Service cannot stop itself and do others things, so it twists another executable file that does some work. getting this right is difficult, and it's especially bad when a new service is built using the newer .NET Framework (such as the recent switch from .Net 2.0 to .net 4.0). The problem is that the .NET 2.0 library cannot work with the .Net 4.0 service.
Now, one approach would be for the older version of the service to run a helper program that comes with the newer version, but ... what if this userβs behavior needs to be changed by a break? I feel more confident not to mix versions, even if some things usually stay the same - it helps reduce design complexity.
Now, apparently, there is a neutral version of .NET for working in Windows services: sc.exe tool: http://support.microsoft.com/kb/251192
I wonder if this is really the silver bullet I was looking for. Now, because I will call this guy programmatically and check for errors, then I could also use the API for this. Ideally, I would have one native C ++ project that compiles into native exe that interacts with SC.exe. Is it possible? If not, how can I find the localization of sc.exe on different computers? They can be 32-bit or 64-bit and run any version of Windows, starting with Windows XP SP2 / 3.
Let me know if you have questions about my question or any brilliant idea or answer to the exact question I asked here.
Edit: if I try to install service 4.0 using 2.0 code, I get the same error as me:
> C:\Windows\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe MyService4.exe
Microsoft (R) .NET Framework Installation Version Version 2.0.50727.4927 Copyright (c) Microsoft Corporation. All rights reserved.
An exception occurred during initialization of the installation: System.BadImageFormatException: it is possible not to load the file or assembly 'file: /// [path] \ MyService4.exe' or one of its dependencies. This assembly is built at runtime, but the runtime is currently loaded and cannot be loaded ..