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 3421790
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:08:31+00:00 2026-05-18T06:08:31+00:00

I need to create a service remotely and would rather not break out to

  • 0

I need to create a service remotely and would rather not break out to a command and run “sc \remotemachine create ……” and want to do it within the C# code.

However, when running the code even though the sc command works quite happily and thus is managing the remote system the ManagementScope.Connect call is throwing an exception with “The RPC server is unavailable.”

A snippet of code that does this is

string machineName = "othermachine";
string path = string.Format(@"\\{0}\root\cimv2", machineName);
ManagementScope scope = new ManagementScope(path);
scope.Connect();

as this is about the first step on the journey I’m a bit stuck as to where to go next. The sc command works, so what is it doing different (other than not using .net libraries – maybe I need to hit the winapi harder?)

Thanks

  • 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-18T06:08:32+00:00Added an answer on May 18, 2026 at 6:08 am

    After pondering this for a little while seeing the time assigned to this task being erroded away I got the old WIN32 api documentation out and [DllImport]’ed the calls I needed to do this the “old fashioned way”. Being an old C dog I used to know my way around these calls, amazing how much comes back even after quite a few years of using the managed libraries.

    What I needed to do was to be able to create a servcie, start it up, do useful work, stop it and delete it. The create, start, stop and delete are mechanics and I wanted to concentrate on the “do useful work” part of the activity.

    I first copied the service’s exe to the ADMIN$ share and verified the local path to that (with our server admins there is no telling!). To do this I call

    ["netapi32.dll"]NetShareGetInfo 
    

    and then I used the following with from advapi32.dll

    • OpenSCManager
    • CreateService
    • StartService
    • OpenService (for when I want to stop and delete it – don’t keep the handles open as this may take a while so cleaner to keep thngs self contained)
    • ControlService
    • QueryServiceStatus
    • CloseServiceHandle

    This all works even across the VPN connection.

    I can only guess that the managed api is trying to do far more than I actually need – the difference in time taken using the managed api and the Windows api is quite a lot, and with no guarantees that the managed api will get through it wasn’t a suitable way forward.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a windows service, and I am not sure whether to
I need to create windows service that would: download some files from uri (google.com,
I need to create windows service that would: download some files from uri (google.com,
Hi I need to create a service that runs a piece of code in
I create a service in Delphi. I need this service to run my program.
I create service and I need create class MyErrors (not exception) My web method
Anybody knows how to do this? I need to create a service that will
I need to create some windows service which will execute every N period of
I need to create a photo gallery service that is managed by users. I've
I need to create a service that will return XML containing data from the

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.