Brendan Tompkins [MVP]

Sponsors

The Lounge

News

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
Programmatically Remote Control a Windows Service

I just thought this was cool, start and stop remote services like so:

System.ServiceProcess.ServiceController sc2 =

new System.ServiceProcess.ServiceController("ServiceName", "MACHINE_NAME");
if
(sc2.Status.Equals(System.ServiceProcess.ServiceControllerStatus.Running))
{
  sc2.Stop();
}

Today' music tip: Run, don't walk to CDNOW to get the new Outkast album... Speakerboxxx/The Love Below.  The track “Hey Ya” is soooooo good.  And only $17 for two separate albums!


Posted 10-09-2003 1:51 AM by Brendan Tompkins
Filed under:

[Advertisement]

Comments

ssr wrote re: Programmatically Remote Control a Windows Service
on 04-29-2004 6:06 AM
How come my app doesnt recognize the ServiceProcess namespace. I get the messages; "ServiceProcess is not a member of System" and "System.ServiceProcess.ServiceController is not defined. "

thanks.
Rob Reagan wrote re: Programmatically Remote Control a Windows Service
on 05-29-2004 12:17 PM
You have to include a reference to the System.ServiceProcess library before you can see the ServiceController class.

Rob
bvn wrote re: Programmatically Remote Control a Windows Service
on 06-23-2004 12:15 PM
Hello there,

We have it working as suggested in Windows XP.
How come the code provided does not work on Windows 2003 Server with .NET 1.1.4322?

The following error message returned:

System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.InvalidOperationException: Cannot open ERPPartySubscriber service on computer '.'. ---> System.ComponentModel.Win32Exception: Access is denied --- End of inner exception stack trace --- at System.ServiceProcess.ServiceController.GetServiceHandle(Int32 desiredAccess) at System.ServiceProcess.ServiceController.Start(String[] args) at System.ServiceProcess.ServiceController.Start() at Intuit.XI.XIServiceController.WindowsServiceController.StartService(String serviceName) in c:\integration platform 2.0\master\xiservicecontroller\windowsservicecontroller.asmx.cs:line 242 --- End of inner exception

Any clues?

Thank you,

B. Nguyen
nishi wrote re: Programmatically Remote Control a Windows Service
on 08-13-2004 7:12 PM
MACHINE_NAME - >

Boss , i am reasonably a fresher
default , machine name comes as '.'
for a service controller object.
So , when i give start() thru program ,
it says , it cant start service on '.' computer.
How can i soleve this?

Thanks
in advance
nishi wrote re: Programmatically Remote Control a Windows Service
on 08-18-2004 8:25 PM
Got it done.
When impersonate was removed , it worked fine.
renuka wrote re: Programmatically Remote Control a Windows Service
on 11-19-2004 1:00 AM
when i give start() thru program ,
it says , it cant start service on '.' computer.
How can i soleve this?
abc wrote re: Programmatically Remote Control a Windows Service
on 04-21-2005 1:48 PM
Nishi, what do you mean by 'When impersnate was removed' ? Please elaborate.
default wrote re: Programmatically Remote Control a Windows Service
on 01-23-2007 12:43 PM

I'm only replying to this because it iss the first google hit for the exception... :-)

Check permissions on the account trying to manage the service. That should clear everything up

Kartik wrote re: Programmatically Remote Control a Windows Service
on 04-14-2008 5:57 AM

You are  saying that  it connects remote machine to manage service which is running on it. So which port it use to connect remote machine.

venky wrote re: Programmatically Remote Control a Windows Service
on 01-12-2009 6:31 AM

Hi guys here also the same problem .

i tried the same service controller it works perfectly with XP machine.

but in the case of windows server 2003 sp2 (don't know about sp1 case)

log is here

LogType:ErrorMessage ErrorMessage:Cannot open Servicename service on computer 'Competername'.;InnerExcpetion:Access is denied ExceptionDetails:   at System.ServiceProcess.ServiceController.GetServiceHandle(Int32 desiredAccess)

  at System.ServiceProcess.ServiceController.Start(String[] args)

  at System.ServiceProcess.ServiceController.Start()

  at ListenerServicesManagement.startService(String serviceName, String machineName, String userName) InnerException:System.ComponentModel.Win32Exception: Access is denied UserName:admin LogTime:1/12/2009 4:55:48 PM

Can anyone help about this issue.... it is really urgent

Sagar wrote re: Programmatically Remote Control a Windows Service
on 01-19-2009 2:07 AM

I am facing the following problem

When I give start() service

I get the exception as, "it cant start service on '.' computer."

Please help... thanks in advance

NewEra wrote re: Programmatically Remote Control a Windows Service
on 05-01-2009 11:26 PM

[url="http://buy-online-viagra.nexo.com"]BUY VIAGRA ONLINE[/url]