473,715 Members | 5,945 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Stopping Windows Management Instrumentation with ServiceControll er

I use the following method to stop the WMI service:

string serviceName = "Windows Management Instrumentation "
public static void stopService(str ing serviceName)
{
ServiceControll er[] services = ServiceControll er.GetServices( );
foreach (ServiceControl ler svc in services)
{
if (svc.DisplayNam e == serviceName)
{
try
{
svc.Stop();
}
catch (System.Service Process.Timeout Exception ex)
{
Console.WriteLi ne(ex.Message);
}
catch (Exception ex)
{
Console.WriteLi ne(ex.Message);
}
Console.WriteLi ne("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 3266

"Primera" <Pr*****@discus sions.microsoft .com> wrote in message
news:60******** *************** ***********@mic rosoft.com...
I use the following method to stop the WMI service:

string serviceName = "Windows Management Instrumentation "
public static void stopService(str ing serviceName)
{
ServiceControll er[] services = ServiceControll er.GetServices( );
foreach (ServiceControl ler svc in services)
{
if (svc.DisplayNam e == serviceName)
{
try
{
svc.Stop();
}
catch (System.Service Process.Timeout Exception ex)
{
Console.WriteLi ne(ex.Message);
}
catch (Exception ex)
{
Console.WriteLi ne(ex.Message);
}
Console.WriteLi ne("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*****@discus sions.microsoft .com> wrote in message
news:60******** *************** ***********@mic rosoft.com...
I use the following method to stop the WMI service:

string serviceName = "Windows Management Instrumentation "
public static void stopService(str ing serviceName)
{
ServiceControll er[] services = ServiceControll er.GetServices( );
foreach (ServiceControl ler svc in services)
{
if (svc.DisplayNam e == serviceName)
{
try
{
svc.Stop();
}
catch (System.Service Process.Timeout Exception ex)
{
Console.WriteLi ne(ex.Message);
}
catch (Exception ex)
{
Console.WriteLi ne(ex.Message);
}
Console.WriteLi ne("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*****@newsgr oups.nospam> wrote in message
news:40******** *************** **@msnews.micro soft.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*****@discus sions.microsoft .com> wrote in message
news:60******** *************** ***********@mic rosoft.com...
I use the following method to stop the WMI service:

string serviceName = "Windows Management Instrumentation "
public static void stopService(str ing serviceName)
{
ServiceControll er[] services = ServiceControll er.GetServices( );
foreach (ServiceControl ler svc in services)
{
if (svc.DisplayNam e == serviceName)
{
try
{
svc.Stop();
}
catch (System.Service Process.Timeout Exception ex)
{
Console.WriteLi ne(ex.Message);
}
catch (Exception ex)
{
Console.WriteLi ne(ex.Message);
}
Console.WriteLi ne("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 programmaticall y
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*****@newsgr oups.nospam> wrote in message
news:40******** *************** **@msnews.micro soft.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*****@discus sions.microsoft .com> wrote in message
news:60******** *************** ***********@mic rosoft.com...

I use the following method to stop the WMI service:

string serviceName = "Windows Management Instrumentation "
public static void stopService(str ing serviceName)
{
ServiceControll er[] services = ServiceControll er.GetServices( );
foreach (ServiceControl ler svc in services)
{
if (svc.DisplayNam e == serviceName)
{
try
{
svc.Stop();
}
catch (System.Service Process.Timeout Exception ex)
{
Console.WriteLi ne(ex.Message);
}
catch (Exception ex)
{
Console.WriteLi ne(ex.Message);
}
Console.WriteLi ne("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.Diagnost ics.Start method.

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

Willy.

"Adam Stocks" <Pr*****@newsgr oups.nospam> wrote in message
news:40******** *************** **@msnews.micro soft.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
programmaticall y 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*****@newsgr oups.nospam> wrote in message
news:40******** *************** **@msnews.micro soft.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*****@discus sions.microsoft .com> wrote in message
news:60******** *************** ***********@mic rosoft.com...

> I use the following method to stop the WMI service:
>
> string serviceName = "Windows Management Instrumentation "
> public static void stopService(str ing serviceName)
> {
> ServiceControll er[] services = ServiceControll er.GetServices( );
> foreach (ServiceControl ler svc in services)
> {
> if (svc.DisplayNam e == serviceName)
> {
> try
> {
> svc.Stop();
> }
> catch (System.Service Process.Timeout Exception ex)
> {
> Console.WriteLi ne(ex.Message);
> }
> catch (Exception ex)
> {
> Console.WriteLi ne(ex.Message);
> }
> Console.WriteLi ne("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
7197
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 was amazed how easy it became to access just about anything under the hood (later versions of NT, 2000, XP) using a couple of lines of code! If you have privileged access to remote computers you can interrogate them as well. My attempts to modify...
4
15891
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 : microsoft.public.dotnet.languages.csharp URL :...
3
4474
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 help would be greatly appreciated. Rob
4
8829
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 up, I run a basic WMI query to check whether WMI is installed. Clearly, there are some issues with older versions of Windows not having WMI
1
3659
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 referenced by the main application compiles properly. When I compile the main application, I have the following message: Cannot copy assembly 'MyLib' to file 'D:\Development\Projects\MyClent\MyLib.dll'. The requested operation cannot be performed...
2
7707
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();
10
7536
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 onstop it fails to stop and status remain 'stopping' Later i can't do anything on that service even i can't uninstall that service.
3
2595
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 Service, and Event Log tells... Event Type: Information Event Source: MsiInstaller Event Category: None Event ID: 11707
3
2517
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 the Windows Service?
0
8821
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8718
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
9340
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9196
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
9103
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,...
1
6646
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4738
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3175
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
3
2118
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.