Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1016119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:30:08+00:00 2026-05-16T10:30:08+00:00

We have built a Windows Service that is running on client’s machines, which occasionally

  • 0

We have built a Windows Service that is running on client’s machines, which occasionally downloads a newer version of itself, and then performs a self-update: installs a new service, starts it, stops the old one, and eventually deletes it. The service cannot stop itself directly and do other stuff, so it spins another executable, which does some of the work. getting this right is tricky, and this is particularly bad when the newer service is built using a newer .Net Framework (such as the recent switch from .Net 2.0 to .net 4.0). The problem is that a .Net 2.0 library cannot operate on a .Net 4.0 service.

Now, one approach would be to have the older version of the service spin a helper program which comes with the newer version, but … what if the behavior of it HAS to change in a breaking way? I feel safer about not mixing up the versions, even if some things usually stay the same – helps to keep the design complexity down.

Now, there appears to be a .Net version-neutral way of operating on Windows Services: the sc.exe tool: http://support.microsoft.com/kb/251192

I wonder if it is indeed the silver bullet that I was seeking. Now, because I will be calling this guy programmatically, and checking for errors, then I might as well use an API for this. Ideally I would have one native C++ project, which compiles to a native exe, which interfaces with SC.exe. Is this possible? If not, then how can I go about locating sc.exe on different computers? They could be 32-bit or 64-bit, and running any version of Windows starting with Win XP SP2/3.

Let me know if you have questions about my question, or some ingenious idea, or an answer to the exact question that I posed here.


Edit: If I try to install a 4.0 service using 2.0 code, I get the same error as if I do:

> C:\Windows\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe MyService4.exe

Microsoft (R) .NET Framework
Installation utility Version
2.0.50727.4927 Copyright (c) Microsoft Corporation. All rights reserved.

Exception occurred while initializing
the installation:
System.BadImageFormatException: Could
not load file or assembly
‘file:///[path]\MyService4.exe’ or one
of its dependencies. This assembly is
built by a runtime newer than the
currently loaded runtime and cannot be
loaded..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:30:08+00:00Added an answer on May 16, 2026 at 10:30 am

    Your native C++ app can call the functions documented here: http://msdn.microsoft.com/en-us/library/ms685942(v=VS.85).aspx (the SCM API that others have mentioned)

    You’ll want to do something along the lines of

    OpenSCManager
    OpenService (or CreateService)
    ChangeServiceConfig
    CloseServiceHandle
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have built a .NET Windows Service that we install on client PCs to
I have a windows service which spawns off long-running tasks while polling for them.
I have built a windows service application in VB.net 2008, and used the Setup
I have a Windows service built upon ATL 7's CAtlServiceModuleT class. This service serves
I have a windows service which fetches data from various datasources and build a
I have built a windows C++ application that I'd like to port to linux.
I have some code which is built both on Windows and Linux. Linux at
I currently have a c++ application that gets built on xp and windows vista/7
I have been working on many applications which run as windows service or scheduled
I have an application that is a not so simple Windows service (C#). I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.