Microsoft MVP성태의 닷넷 이야기
개발환경 구성 : 24. Smart Start and Stop Service in VS.NET Build [링크 복사], [링크+제목 복사],
조회: 11130
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

Smart Start and Stop Service in VS.NET Build
; http://blogs.msdn.com/irenak/archive/2006/09/13/752075.aspx

NT 서비스 프로그램에 대한 빌드를 할 때, 빌드 이벤트로 넣어두면 좋겠지요. ^^

If you have a windows service project as part of your solution, you’re quite familiar with the issues it presents -- if the service is running and you’re recompiling either the service project itself, or any assemblies loaded by the service, you’ll get a build error. The script below, courtesy of Scott Jennings, is a way to stop and start service, if it’s installed and is running/stopped correspondingly. All that remains to do it to add the script invocation code to pre-build and post-build event command lines in Visual Studio.

' Usage:

' start /w wscript "\ServiceHelper.vbs"

' Example:

' start /w wscript "C:\Projects\XYZ\ServiceHelper.vbs" start myservice

Dim WMIService

Dim Services

Dim Service

Dim action

Dim result

If Wscript.Arguments.Count <> 2 Then

Wscript.Echo "Usage: ServiceHelper.vbs start|stop ServiceName"

Wscript.Quit 1

End If

Set WMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

Set Services = WMIService.ExecQuery("Select * from Win32_Service where Name = '" + Wscript.Arguments(1) + "'")

If Services.Count > 1 Then

Wscript.Echo "More than one matching service"

Wscript.Quit 1

ElseIf Services.Count = 1 Then

action = Wscript.Arguments(0)

For Each Service In Services

If action = "start" AND Service.State <> "Running" Then

result = Service.StartService()

ElseIf action = "stop" AND Service.State <> "Stopped" Then

result = Service.StopService()

End If

Next

Wscript.Quit(result)

Else

Wscript.Echo "No such service found"

Wscript.Quit 1

End If

Special thanks to Scott Jennings who created this solution!








[최초 등록일: ]
[최종 수정일: 9/14/2006]


비밀번호

댓글 작성자
 




... [16]  17  18  19  20  21  22  23  24  25  26  27  28  29  30  ...
NoWriterDateCnt.TitleFile(s)
800정성태7/10/200712161.NET 3.5 : 27. IQueryable 구현 방법 [3]
799정성태7/6/200710258VS.NET IDE : 36. MSBee 를 이용한 .NET 1.1 용 프로젝트 빌드
798정성태7/4/200710972VS.NET IDE : 35. 업데이트 - Publish Website hotfix for VS 2005 SP1
797정성태7/3/200711155Debug : 21. Image File Execution Options 키 동작 방식 [1]
796정성태7/3/200712622.NET 3.5 : 26. WCF - WebServiceHost
795정성태6/29/200713161Windows Update "사용 약관 읽기" 화면 잘림 현상
794정성태6/29/200711969Visual C++ : 11. Orcas - 마샬링 라이브러리
793정성태6/28/200711933TFS : 109. Daily Build파일 다운로드1
792정성태6/28/200711392개발 환경 구성: 104. Internet Explorer - Local Intranet 판단 옵션
791정성태6/25/200711744TFS : 108. Orcas - Continuous Integration 지원 [1]
790정성태6/24/200711839개발 환경 구성: 103. Internet Explorer 와 관련된 각종 개발 도구들
789정성태6/23/200712335Vista : 47. 비스타에서만 사용가능한 Managed 기능들 (2)
788정성태6/21/200712444개발 환경 구성: 102. Windows환경에서의 OpenSSL설치파일 다운로드1
787정성태6/21/200712131개발 환경 구성: 101. HttpSimulator
786정성태6/21/200712133TFS : 107. Team Build 와 다중 프로젝트 빌드 설정
785정성태6/19/200713007Vista : 46. 탐색기에서의 네트워크 파일 복사가 느린 문제를 해결하는 방법
784정성태6/19/200712108Windows 2008 : 3. 주요 변화 10가지
783정성태6/18/200713455SDK : 10. IERefreshElevationPolicy Win32 API
782정성태6/17/200711776.NET : 60. 프로젝트에서 참조한 Unmanaged DLL 을 GAC 에 배포하는 방법
781정성태6/16/200713389.NET 3.5 : 25. LINQ 와 동적 쿼리
780정성태6/16/200712490개발 환경 구성: 100. Windows 2008 - 터미널 서비스 Drain 모드
779정성태6/15/200712181SDK : 9. Windows SDK 구분하기
778정성태6/13/200712108Web : 1. Silverlight - Programming HTML with C#
777정성태6/13/200711615TFS : 106. Microsoft eScrum Version 1.0
776정성태6/13/200711884.NET 3.0 : 21. WPF 실습 - Outlook 2007 스타일의 응용 프로그램 개발
775정성태6/11/200712013TFS : 105. Visual Studio Team Foundation Server ? Project Server 2007 Connector
... [16]  17  18  19  20  21  22  23  24  25  26  27  28  29  30  ...