473,769 Members | 5,374 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Windows Service Controller Exception - Why?

I have this code:

System.ServiceP rocess.ServiceC ontroller sc = new
System.ServiceP rocess.ServiceC ontroller("MySe rvice");

if(sc.Status == System.ServiceP rocess.ServiceC ontrollerStatus .Stopped)

{

sc.Start();

}

sc.WaitForStatu s(System.Servic eProcess.Servic eControllerStat us.Running,new
TimeSpan(0,0,0, 30,0));

if(sc.Status == System.ServiceP rocess.ServiceC ontrollerStatus .Running)

{

try

{

sc.ExecuteComma nd(1); //exception happens here

}

catch(System.Ex ception ex)

{

sc.Stop();
sc.WaitForStatu s(System.Servic eProcess.Servic eControllerStat us.Stopped);

MessageBox.Show (ex.Message);

Application.Exi t();

}

}

the sc.ExcecuteComm and(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 1158

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

Similar topics

3
377
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 can’t find any command or methods for stopping the service from running any further. can anyone help?
12
2779
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 configuration settings, and if anything is either empty, or invalid (such as a DB DataSource string or a missing diredtory, etccc) I don't want the servie to start. So how would I cancel the start up?
23
7594
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 unrecoverable error occurs. When that case occurs, I create a ServiceController object and call the Stop() method. However - I get an exception thrown saying access denied. If I switch to using the LocalService account it works fine, but I lose...
7
2363
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 http://www.dotnetmonster.com
4
4182
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 check to see if the status is in stopped or running mode. But that doesn't tell me if it is actually running. I need to know this so that if it happens I can programmatically start the same service on another machine.
7
7233
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 this error. I want to restart my windows service every time the COM object throws an error. I use System.ServiceProcess.ServiceController to stop and start my service. But there is one thing I do not understand:
2
7708
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 machine name to my machine name then also it does not work. Below is the code ServiceController controller = new ServiceController();
3
7441
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 with this I need an option to show the windows application which my service has started as a result of its invokation. So I have written a service control by adding a new project of type
1
15218
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 can no longer connect to the domain controller. Ping resolves the domain controllers name to the correct ip nslookup finds the ip but can not resolve the name. When I attempt to log on to a machine on the domain it takes around twenty minutes...
2
855
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 report program, as the report needs to see the latest data being updated by this service. This is the code i am using. ServiceController controller = new ServiceController(); controller.ServiceName = "S1";
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10049
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9996
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5307
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3964
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3564
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.