473,395 Members | 1,653 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,395 software developers and data experts.

Windows Service Controller Exception - Why?

I have this code:

System.ServiceProcess.ServiceController sc = new
System.ServiceProcess.ServiceController("MyService ");

if(sc.Status == System.ServiceProcess.ServiceControllerStatus.Stop ped)

{

sc.Start();

}

sc.WaitForStatus(System.ServiceProcess.ServiceCont rollerStatus.Running,new
TimeSpan(0,0,0,30,0));

if(sc.Status == System.ServiceProcess.ServiceControllerStatus.Runn ing)

{

try

{

sc.ExecuteCommand(1); //exception happens here

}

catch(System.Exception ex)

{

sc.Stop();
sc.WaitForStatus(System.ServiceProcess.ServiceCont rollerStatus.Stopped);

MessageBox.Show(ex.Message);

Application.Exit();

}

}

the sc.ExcecuteCommand(1) throws the following exception:

Cannot control MyService service on computer "."

the inner exception is: Access Denied

My question is: Why can I start, stop, etc. MyService but not use the
ExecuteCommand method?

Thanks!

Tom
Nov 15 '05 #1
0 1146

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Xman | last post by:
Can anyone tell how to stop a service from within the service, example: On starting the service needs a file from the disk if it does not find the file i need the service stop and end. But I...
12
by: JSheble | last post by:
I've written a Windows Service using C#, but I cannot seem to figure out how to cancel or prevent the service from starting under certain conditions. For example, in the OnStart I read in some...
23
by: Adam Clauss | last post by:
I have a C# Windows Service running as the NetworkService account because it needs to access a network share. As part of the service's initialization, I want the service to terminate, if an...
7
by: dotnetprogrammer via DotNetMonster.com | last post by:
I have an NT Service written in c# (.net framwork 2.0). When it hits a certain error condition, I want it to be to cause itself to stop. How can I do this? -- Message posted via...
4
by: tshad | last post by:
What would be a good way to check programmatically whether a service was running? We have a service that dies periodically and I need to check to see if this service is running. I know how to...
7
by: shai | last post by:
I am working at .net 1.1, writing in c#. I have windows service with a COM object. Every unexpected time The COM object throw an error that make my service get stuck (do not respond). I can catch...
2
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello everyone, I have this application that stops and starts IIS admin. When I try to stop the service. I get an error "Cannot open IISADMIN service on computer '.'.". I tried changing the...
3
by: sonu | last post by:
Hello all, I am trying to develop an application which will run as a windows service. The application should have Normal options available with service like start, stop and pause but along...
1
by: eblackmo | last post by:
I have a test network consisting of four servers running windows 2003 server R2 SP2. I have set up a domain which functioned correctly for about a day and a half until the other servers decided they...
2
by: ramaswamynanda | last post by:
Hello, I have written a windows service , S1 , that is scheduled to run daily. It reads some files and updates the database. It works well . A requirement has arisen to call this service from a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.