By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,369 Members | 1,253 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,369 IT Pros & Developers. It's quick & easy.

Stopping Windows Management Instrumentation with ServiceController

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a

"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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.