Microsoft MVP성태의 닷넷 이야기
개발환경 구성 : 24. Smart Start and Stop Service in VS.NET Build [링크 복사], [링크+제목 복사],
조회: 11121
글쓴 사람
정성태 (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]


비밀번호

댓글 작성자
 




1  2  3  4  5  6  7  8  9  10  11  12  [13]  14  15  ...
NoWriterDateCnt.TitleFile(s)
875정성태11/9/200710364.NET : 66. 한 눈으로 확인하는 .NET 데이터 액세스 계층
874정성태11/6/200711420Debug : 30. OpenFileDialog 사용시 메모리 사용이 급격하게 올라가는 문제
873정성태11/6/200710487Debug : 29. WinDBG - 명령어 !IToldYouSo
872정성태11/3/200710594Debug : 28. Debugger Visualizer - DynamicMethod / MethodInfo [1]
871정성태10/31/200710809TFS : 141. VS.NET 2008 - 개선된 WorkItem 기능
870정성태10/31/200710488TFS : 140. TFS to TFS Migration Tool
869정성태10/31/200710623.NET : 65. ASP.NET 을 어셈블리 언어로.
868정성태10/30/200710859.NET 3.0 : 23. 카드 스페이스 - SSL 없이도 구현가능.
867정성태10/30/200710751.NET : 64. CAB(Composite Application Block) 에 접근하고 싶으세요?
866정성태10/28/200710693개발 환경 구성: 115. VPC 를 이용한 AD 네트워크 구성
865정성태10/27/200710851.NET : 63. Singleton 패턴 구현
864정성태10/23/200710878TFS : 139. 단위 테스트를 MTA로 실행하도록 설정 [1]
863정성태10/20/200710621VisualNDepend
862정성태10/20/200710128.NET : 62. CAB 성능 향상 팁
861정성태10/20/200710507Debug : 27. SOS 를 이용하여 .NET Finalizer 디버깅
860정성태10/18/200710500TFS : 138. 팀 규모에 따른 물리 서버의 용량
859정성태10/16/200711423개발 환경 구성: 114. Eric Gunnerson 의 WiX 관련 포스트들 [3]
858정성태10/16/200710735.NET : 61. 메서드 안에서 정의된 블록 내부의 변수에 대한 범위
857정성태10/9/200710359TFS : 137. 특정 버전의 소스로 팀 빌드하는 방법
856정성태10/8/200711739.NET 3.5 : 32. ReaderWriterLock 과 ReaderWriterLockSlim 의 성능 비교.
855정성태10/5/200710483개발 환경 구성: 113. Virtual PC - 처음 생성한 VHD 파일의 크기를 바꿀 수 있을까?
854정성태10/3/200710355TFS : 136. Operations Guidance for Team Foundation Server
853정성태10/2/200710746.NET 3.5 : 31. ToJSON 확장 메서드 구현
852정성태9/30/200711874IIS : 18. IIS 7.0 의 FTP 서비스를 위한 방화벽 설정
851정성태9/27/200710912TFS : 135. TFS 2008 용 빌드 알림 도구
850정성태9/26/200710177TFS : 134. Visual Studio Team System Web Access 2008 파워툴 CTP
1  2  3  4  5  6  7  8  9  10  11  12  [13]  14  15  ...