본문 바로가기

IT/.NET

[.NET] ServiceController

Windows 서비스를 나타내며 이 클래스를 사용하면 실행 중이거나 중지된 서비스에 연결하거나 서비스를 조작하거나 서비스 관련 정보를 가져올 수 있습니다.

네임스페이스:  System.ServiceProcess
어셈블리:  System.ServiceProcess(System.ServiceProcess.dll)

http://msdn.microsoft.com/ko-kr/library/7fs05y7h(v=VS.90).aspx



System.ServiceProcess


System.ServiceProcess 네임스페이스는 Windows 서비스 응용 프로그램을 구현, 설치 및 제어할 수 있는 클래스를 제공합니다. 서비스는 사용자 인터페이스 없이 실행되는 장기 실행 파일입니다. 서비스 구현은 ServiceBase 클래스에서 상속 및 시작, 중지, 일시 중지, 계속 명령이 전달될 때 처리할 특정 동작 정의뿐만 아니라 시스템이 종료될 때 적용할 사용자 지정 동작과 작업 정의를 포함합니다....
http://msdn.microsoft.com/ko-kr/library/3kwsb404(v=VS.90).aspx



Example


using System.ServiceProcess;

String ServiceName = "서비스명";
ServiceController sc = new ServiceController(ServiceName);
sc.Start();

sc.Status.toString();
if (sc.Status == ServiceControllerStatus.Running)
    MessageBox.Show("The service is running.");

sc.Stop();



ServiceControllerStatus


ContinuePending : 서비스 계속 명령이 보류 중입니다.
Paused : 서비스가 일시 중지되었습니다.
PausePending : 서비스 일시 중지 명령이 보류 중입니다.
Running : 서비스가 실행되고 있습니다.
StartPending : 서비스가 시작되었습니다.
Stopped : 서비스가 실행되고 있지 않습니다.
StopPending : 서비스가 중지되었습니다.


ServiceController Method




버전 정보
.NET Framework
3.5, 3.0, 2.0, 1.1, 1.0에서 지원