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

Stopping Windows Management Instrumentation with ServiceController

I use the following method to stop the WMI service:

string serviceName = "Windows Management Instrumentation"
public static void stopService(string serviceName)
{
ServiceController[] services = ServiceController.GetServices();
foreach (ServiceController svc in services)
{
if (svc.DisplayName == serviceName)
{
try
{
svc.Stop();
}
catch (System.ServiceProcess.TimeoutException ex)
{
Console.WriteLine(ex.Message);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.WriteLine("The {0} process was stopped.",
serviceName);
}

}
}

According to Event Viewer the system is sent a stop control to WMI, and then
the service stops. A second or so later the WMI service restarts for no
apparent reason. Any advice on how to keep the WMI service stopped would be
greatly appreciated. I am new to C# so if you see any problems with my
method or can suggest a better way to do this please let me know. Thanks in
advance.
Jan 4 '06 #1
5 3243

"Primera" <Pr*****@discussions.microsoft.com> wrote in message
news:60**********************************@microsof t.com...
I use the following method to stop the WMI service:

string serviceName = "Windows Management Instrumentation"
public static void stopService(string serviceName)
{
ServiceController[] services = ServiceController.GetServices();
foreach (ServiceController svc in services)
{
if (svc.DisplayName == serviceName)
{
try
{
svc.Stop();
}
catch (System.ServiceProcess.TimeoutException ex)
{
Console.WriteLine(ex.Message);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.WriteLine("The {0} process was stopped.",
serviceName);
}

}
}

According to Event Viewer the system is sent a stop control to WMI, and
then
the service stops. A second or so later the WMI service restarts for no
apparent reason. Any advice on how to keep the WMI service stopped would
be
greatly appreciated. I am new to C# so if you see any problems with my
method or can suggest a better way to do this please let me know. Thanks
in
advance.


As you can stop a service, other applications and services can start a
service, right?
WMI is s system service you should not stop it unless you realy have good
reasons to do so. If you don't want WMI to run at all disable the service,
but note that I said it's a "system service" that means other services and
applications may depend on it.

Willy.
Jan 4 '06 #2
Yes...I agree that WMI is definitely a required service. I have to stop
it briefly so that I can delete all contents of the Repository folder. Then
when WMI is restarted the correct Repository data is regenerated. We have
experienced a unique problem where WMI becomes corrupted and the SMS Client
app will not work properly. The fix is to stop the WMI service, delete the
data in Repository, restart the WMI service, remove/clean any current SMS
Client, and reinstall the SMS Client. So...the purpose of this app is to
automate that procedure. Would you happen to have any advice on how to accomplish
this? All advice and help is greatly appreciated.

Hello Willy Denoyette [MVP],
"Primera" <Pr*****@discussions.microsoft.com> wrote in message
news:60**********************************@microsof t.com...
I use the following method to stop the WMI service:

string serviceName = "Windows Management Instrumentation"
public static void stopService(string serviceName)
{
ServiceController[] services = ServiceController.GetServices();
foreach (ServiceController svc in services)
{
if (svc.DisplayName == serviceName)
{
try
{
svc.Stop();
}
catch (System.ServiceProcess.TimeoutException ex)
{
Console.WriteLine(ex.Message);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.WriteLine("The {0} process was stopped.",
serviceName);
}
}
}
According to Event Viewer the system is sent a stop control to WMI,
and
then
the service stops. A second or so later the WMI service restarts for
no
apparent reason. Any advice on how to keep the WMI service stopped
would
be
greatly appreciated. I am new to C# so if you see any problems with
my
method or can suggest a better way to do this please let me know.
Thanks
in
advance.

As you can stop a service, other applications and services can start a
service, right?
WMI is s system service you should not stop it unless you realy have
good
reasons to do so. If you don't want WMI to run at all disable the
service,
but note that I said it's a "system service" that means other services
and
applications may depend on it.
Willy.

Jan 5 '06 #3
Only "work-around" I see is to disable WMI before you stop it, else SMS will
restart it.
Note that the only real solution to this problem is to find out who's
corrupting the repository.
Also note that you should not write anything yourself to do this, the
command line utility sc.exe is the tool for this.

Willy.

"Primera" <Pr*****@newsgroups.nospam> wrote in message
news:40*************************@msnews.microsoft. com...
Yes...I agree that WMI is definitely a required service. I have to stop
it briefly so that I can delete all contents of the Repository folder.
Then when WMI is restarted the correct Repository data is regenerated. We
have experienced a unique problem where WMI becomes corrupted and the SMS
Client app will not work properly. The fix is to stop the WMI service,
delete the data in Repository, restart the WMI service, remove/clean any
current SMS Client, and reinstall the SMS Client. So...the purpose of
this app is to automate that procedure. Would you happen to have any
advice on how to accomplish this? All advice and help is greatly
appreciated.

Hello Willy Denoyette [MVP],
"Primera" <Pr*****@discussions.microsoft.com> wrote in message
news:60**********************************@microsof t.com...
I use the following method to stop the WMI service:

string serviceName = "Windows Management Instrumentation"
public static void stopService(string serviceName)
{
ServiceController[] services = ServiceController.GetServices();
foreach (ServiceController svc in services)
{
if (svc.DisplayName == serviceName)
{
try
{
svc.Stop();
}
catch (System.ServiceProcess.TimeoutException ex)
{
Console.WriteLine(ex.Message);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.WriteLine("The {0} process was stopped.",
serviceName);
}
}
}
According to Event Viewer the system is sent a stop control to WMI,
and
then
the service stops. A second or so later the WMI service restarts for
no
apparent reason. Any advice on how to keep the WMI service stopped
would
be
greatly appreciated. I am new to C# so if you see any problems with
my
method or can suggest a better way to do this please let me know.
Thanks
in
advance.

As you can stop a service, other applications and services can start a
service, right?
WMI is s system service you should not stop it unless you realy have
good
reasons to do so. If you don't want WMI to run at all disable the
service,
but note that I said it's a "system service" that means other services
and
applications may depend on it.
Willy.


Jan 5 '06 #4
Well, this is a rather rare occurrence, and I certainly agree about finding
the corrupting item. I have not been able to identify what has corrupted
WMI, but after taking these steps we have never had a recurrence of the issue
on the same machine. Could you offer any advice on how to programmatically
disable WMI so that I could keep the service stopped long enough to delete
these items? Thanks for your help.
Adam

Hello Willy Denoyette [MVP],
Only "work-around" I see is to disable WMI before you stop it, else
SMS will
restart it.
Note that the only real solution to this problem is to find out who's
corrupting the repository.
Also note that you should not write anything yourself to do this, the
command line utility sc.exe is the tool for this.
Willy.

"Primera" <Pr*****@newsgroups.nospam> wrote in message
news:40*************************@msnews.microsoft. com...
Yes...I agree that WMI is definitely a required service. I have to
stop it briefly so that I can delete all contents of the Repository
folder. Then when WMI is restarted the correct Repository data is
regenerated. We have experienced a unique problem where WMI becomes
corrupted and the SMS Client app will not work properly. The fix is
to stop the WMI service, delete the data in Repository, restart the
WMI service, remove/clean any current SMS Client, and reinstall the
SMS Client. So...the purpose of this app is to automate that
procedure. Would you happen to have any advice on how to accomplish
this? All advice and help is greatly appreciated.

Hello Willy Denoyette [MVP],
"Primera" <Pr*****@discussions.microsoft.com> wrote in message
news:60**********************************@microsof t.com...

I use the following method to stop the WMI service:

string serviceName = "Windows Management Instrumentation"
public static void stopService(string serviceName)
{
ServiceController[] services = ServiceController.GetServices();
foreach (ServiceController svc in services)
{
if (svc.DisplayName == serviceName)
{
try
{
svc.Stop();
}
catch (System.ServiceProcess.TimeoutException ex)
{
Console.WriteLine(ex.Message);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.WriteLine("The {0} process was stopped.",
serviceName);
}
}
}
According to Event Viewer the system is sent a stop control to WMI,
and
then
the service stops. A second or so later the WMI service restarts
for
no
apparent reason. Any advice on how to keep the WMI service stopped
would
be
greatly appreciated. I am new to C# so if you see any problems
with
my
method or can suggest a better way to do this please let me know.
Thanks
in
advance.
As you can stop a service, other applications and services can start
a
service, right?
WMI is s system service you should not stop it unless you realy have
good
reasons to do so. If you don't want WMI to run at all disable the
service,
but note that I said it's a "system service" that means other
services
and
applications may depend on it.
Willy.

Jan 6 '06 #5
Well the only correct way to keep your repository in good shape is by
applying a back-up strategy. For instance you could create a job object that
is run by the scheduler every day at xx, the job can be a simple command
line script that creates a back-up of the repository by issuing the "winmgmt
/backup..." command. Writes to the repository are blocked during back-up,
reads are handled though, clients keep their session if any, only thing that
can happen is a timeout when issuing a write (create/modify object) action,
this should be handled by the application anyway.
Whenever something happens with the repository you can restore the latest
back-up by means of the "winmgmt /restore..." command. Reads and writes from
clients are blocked during restore, but clients aren't disconected.

Note that these commands can also be issued through the
System.Diagnostics.Start method.

Look-up the MSDN docs for details on the winmgmt command line switches.

Willy.

"Adam Stocks" <Pr*****@newsgroups.nospam> wrote in message
news:40*************************@msnews.microsoft. com...
Well, this is a rather rare occurrence, and I certainly agree about
finding the corrupting item. I have not been able to identify what has
corrupted WMI, but after taking these steps we have never had a recurrence
of the issue on the same machine. Could you offer any advice on how to
programmatically disable WMI so that I could keep the service stopped long
enough to delete these items? Thanks for your help.
Adam

Hello Willy Denoyette [MVP],
Only "work-around" I see is to disable WMI before you stop it, else
SMS will
restart it.
Note that the only real solution to this problem is to find out who's
corrupting the repository.
Also note that you should not write anything yourself to do this, the
command line utility sc.exe is the tool for this.
Willy.

"Primera" <Pr*****@newsgroups.nospam> wrote in message
news:40*************************@msnews.microsoft. com...
Yes...I agree that WMI is definitely a required service. I have to
stop it briefly so that I can delete all contents of the Repository
folder. Then when WMI is restarted the correct Repository data is
regenerated. We have experienced a unique problem where WMI becomes
corrupted and the SMS Client app will not work properly. The fix is
to stop the WMI service, delete the data in Repository, restart the
WMI service, remove/clean any current SMS Client, and reinstall the
SMS Client. So...the purpose of this app is to automate that
procedure. Would you happen to have any advice on how to accomplish
this? All advice and help is greatly appreciated.

Hello Willy Denoyette [MVP],

"Primera" <Pr*****@discussions.microsoft.com> wrote in message
news:60**********************************@microsof t.com...

> I use the following method to stop the WMI service:
>
> string serviceName = "Windows Management Instrumentation"
> public static void stopService(string serviceName)
> {
> ServiceController[] services = ServiceController.GetServices();
> foreach (ServiceController svc in services)
> {
> if (svc.DisplayName == serviceName)
> {
> try
> {
> svc.Stop();
> }
> catch (System.ServiceProcess.TimeoutException ex)
> {
> Console.WriteLine(ex.Message);
> }
> catch (Exception ex)
> {
> Console.WriteLine(ex.Message);
> }
> Console.WriteLine("The {0} process was stopped.",
> serviceName);
> }
> }
> }
> According to Event Viewer the system is sent a stop control to WMI,
> and
> then
> the service stops. A second or so later the WMI service restarts
> for
> no
> apparent reason. Any advice on how to keep the WMI service stopped
> would
> be
> greatly appreciated. I am new to C# so if you see any problems
> with
> my
> method or can suggest a better way to do this please let me know.
> Thanks
> in
> advance.
As you can stop a service, other applications and services can start
a
service, right?
WMI is s system service you should not stop it unless you realy have
good
reasons to do so. If you don't want WMI to run at all disable the
service,
but note that I said it's a "system service" that means other
services
and
applications may depend on it.
Willy.


Jan 6 '06 #6

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

Similar topics

6
by: Colin Brown | last post by:
Recently I was looking for remote management tools and came across "Windows Management Instrumentation". There is a python interface available: http://tgolden.sc.sabren.com/python/wmi.html I...
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 :...
3
by: Rob | last post by:
Can a form be opened from a Windows service? I have a windows service that I would like to open a form from a notify icon. I cannot get the Notify Icon to display nor can I open a form. Any...
4
by: Steve Barker | last post by:
Hi guys! I have written a .NET application that uses WMI to iterate through CD drives, in order to detect whether a certain CD has been loaded into the CD Drive. When the application starts...
1
by: =?Utf-8?B?UGllcnJl?= | last post by:
Hello, I have an simle application that uses a referenced library of my own. It's been a year now that I have no problems until a few days. Here is the details of my problem: The library...
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...
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...
3
by: Mika M | last post by:
I'm programming quite simple Windows Service using C# 2005. I also made setup for it into same solution. When I run setup to install service, it's going fine into C:\Program Files\MyCompany\My...
3
by: =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= | last post by:
I've written some test code based on a Help example. Assuming I get a ServiceController using the ServiceController.GetServices call, is there any way to use that to get the executable path of...
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...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.