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

stopping window service through C#

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();
//controller.MachineName = "CS1239876";
controller.MachineName=".";
controller.ServiceName = "IISADMIN";
string status = controller.Status.ToString();
if(status == "Running)
controller.Stop();

Can anyone please help me with this.

Any help will be appreciated.
Mar 21 '07 #1
2 7690
To run the IISADMIN service, you should have admin role in your
system.

The following code is a working code... i tried for Messanger since i
dont have "IISADMIN". I hope you will get ti done if you replace the
service name.

ServiceController controller = new ServiceController();
controller.ServiceName = "Messenger";
label1.Text = controller.Status.ToString();
if (controller.Status == ServiceControllerStatus.Running)
{
controller.Stop();
}
if (controller.Status == ServiceControllerStatus.Stopped)
{
controller.Start();
}

try this....OR try the below
ServiceController controller = new ServiceController("Messenger",
".");
if (controller.Status == ServiceControllerStatus.Running)
{
controller.Stop();
}
if (controller.Status == ServiceControllerStatus.Stopped)
{
controller.Start();
}

Vinki wrote:
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();
//controller.MachineName = "CS1239876";
controller.MachineName=".";
controller.ServiceName = "IISADMIN";
string status = controller.Status.ToString();
if(status == "Running)
controller.Stop();

Can anyone please help me with this.

Any help will be appreciated.
Mar 21 '07 #2
Hello Karthik,

I tried this code below

try
{
// ServiceController controller = new ServiceController();
// //controller.MachineName = "CSCRCAM848327";
// controller.MachineName=".";
// controller.ServiceName = "PDSSvc";
// string status = controller.Status.ToString();
// if(status == "Running")
// controller.Stop();
////////////////////////////////

ServiceController controller = new ServiceController("Messenger", ".");
if (controller.Status == ServiceControllerStatus.Running)
{
controller.Stop();
}
if (controller.Status == ServiceControllerStatus.Stopped)
{
controller.Start();
}


}
catch(Exception ex)
{
string x = ex.Message;
flag=true;
}

It didn't work and I am getting the same error. I have admin rights on my
computer.

"Karthik D V [C#,ASP.NET - MCAD]" wrote:
To run the IISADMIN service, you should have admin role in your
system.

The following code is a working code... i tried for Messanger since i
dont have "IISADMIN". I hope you will get ti done if you replace the
service name.

ServiceController controller = new ServiceController();
controller.ServiceName = "Messenger";
label1.Text = controller.Status.ToString();
if (controller.Status == ServiceControllerStatus.Running)
{
controller.Stop();
}
if (controller.Status == ServiceControllerStatus.Stopped)
{
controller.Start();
}

try this....OR try the below
ServiceController controller = new ServiceController("Messenger",
".");
if (controller.Status == ServiceControllerStatus.Running)
{
controller.Stop();
}
if (controller.Status == ServiceControllerStatus.Stopped)
{
controller.Start();
}

Vinki wrote:
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();
//controller.MachineName = "CS1239876";
controller.MachineName=".";
controller.ServiceName = "IISADMIN";
string status = controller.Status.ToString();
if(status == "Running)
controller.Stop();

Can anyone please help me with this.

Any help will be appreciated.

Mar 21 '07 #3

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

Similar topics

5
by: CG | last post by:
Hi I have developed a Windows Service When I try to start the Service it tells me that it cannot start as there may not be any work to do When I comment out below line of code in my OnStart...
0
by: Daniel O'Brien | last post by:
Hi - any help with this would be greatly appreicated - it has already had me confused for a good few hours! I am using Visual Studio 2003 and the .NET framework 1.1. I have a C# Windows...
4
by: Keith | last post by:
I'm in the same boat as the fellow who posted this message back in August: Title : Windows Service, How does one make a service "fail" properly? Author : Ross Bennett Group :...
7
by: Gene | last post by:
I have a Windows Service (VB.NET) that runs 24/7. It queries a Web service 5 to 10 times per hour. About 2 or 3 times a month, it fails. The log indicates that it sends the request to the Web...
2
by: matteo | last post by:
Hi everyboby, i wrote a c# service that every XXX minute launch a working thread on timer events, something like this: private void timer_Elapsed ( object status ) { // Worker thread...
5
by: chris.hearson | last post by:
How do I programmatically prevent a service from stopping? I want to be able to keep my service running (started), under certain conditions, when a user tries to stop it. I have tried throwing an...
6
by: D | last post by:
I have a simple file server utility that I wish to configure as a Windows service - using the examples of the Python Win32 book, I configured a class for the service, along with the main class...
0
by: archana | last post by:
Hi all, I am having web service which is deployed on windows server 2003. I am using that web service in my windows application. That window service is inserting large amount of data from...
10
by: archana | last post by:
Hi all, I am having one windows service which is updating to database. On 'Onstop i want to wait till current updation complete. How will i do this? Because if i write some lengthy code on...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.