473,385 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

ServiceController .net c#

15
Hi all,

I am trying to controll a service programatically using the ServiceController class .net c#.
It is giving me an error that it cannot find the service name.

I have tried it stopping with the command line using NET, and it works but not with my code!
Can anyone please point me where I might be wrong?

My code:
string SERVICENAME = "TestService";
string SERVERNAME = "ABC" ;
ServiceController myController = new ServiceController();
myController.MachineName = SERVERNAME;
myController.ServiceName = SERVICENAME;
myController.Stop();
myController.Start();

my commandline goes something like this:
C:\test>NET STOP "TestService"

and it works.
I have tried without the machine name, and also with my IP address both failed!

The exact error is something like:
"Cannot open TestService service on computer 'ABC'." "

Thanks in advance!
May 21 '08 #1
3 2899
Plater
7,872 Expert 4TB
Sounds like remote access to services are not allowed?
May 21 '08 #2
MedIt
15
This has been resolved.Apparently the service display name and the service name was different.
Thanks for your response though!
Sounds like remote access to services are not allowed?
May 22 '08 #3
Plater
7,872 Expert 4TB
I had thought of that, but wasn't sure it was even possible as I couldn't think of a service with a different display name vs service name offhand.
Glad you found the solution.
May 22 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: ucasesoftware | last post by:
Dim myController As ServiceController myController = New ServiceController("myWrondName") i try : if myController is nothing then messagebox.show("This service doesn't exist" end if but...
0
by: Anthony Boudouvas | last post by:
Hi to all, i have made a module that can get a list of services running on a local or remote machine. So i have machine A that get a list of services of machine B The way the configuration is...
10
by: Bill Burris | last post by:
How do I set the ServiceType to InteractiveProcess, since this property is read only? Is there a way to set this with code in my Installer class, or a standalone process? I normally set this...
1
by: Tom J | last post by:
What do I have to do to get System.ServiceProcess.ServiceController.ExecuteCommand(int) to work? I have written a service that overrides OnCustomCommand to handle commands sent to it. If I...
2
by: Jonathan Leonard | last post by:
Hello, I'm using the .NET class ServiceController to start my service. After calling start, a subsequent call to ServiceController.Status is returning 'stopped.' I know the service is running...
2
by: Vadim Rapp | last post by:
Hello, I have the following code: ========== Dim RemoteService As System.ServiceProcess.ServiceController RemoteService = New System.ServiceProcess.ServiceController("service1",...
5
by: Primera | last post by:
I use the following method to stop the WMI service: string serviceName = "Windows Management Instrumentation" public static void stopService(string serviceName) { ServiceController services =...
3
by: Bram Hoefnagel | last post by:
Hi, On the 1.1 framework I couldn't find a solution to get a list of services from an other PC. Only a list of services on My local PC. (witch is strange i guess, as you look to the MSDN doc.) ...
7
by: =?Utf-8?B?YXVsZGg=?= | last post by:
hello, i'm try to research the way to open a remote machine's to collect the services and processes. i have the local data collection running but i can not figure out what MSDN or the C# help file...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.