Microsoft MVP성태의 닷넷 이야기
개발환경 구성 : 24. Smart Start and Stop Service in VS.NET Build [링크 복사], [링크+제목 복사],
조회: 11145
글쓴 사람
정성태 (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)
625정성태2/2/20079581TFS : 73. Team System 관련 유틸리티 목록
624정성태2/1/200710732개발 환경 구성: 72. Fiddler - IE 7 + Cassini 에서 동작되지 않는 문제 [2]
623정성태2/1/20079927TFS : 72. TFS 언어 변경
622정성태1/30/20079532.NET : 53. ASP.NET 2.0 AJAX Extension 1.0 - 소스 코드
621정성태1/30/200710104TFS : 71. Code Analysis 정책을 유형에 따라 적용하는 방법
620정성태1/29/200710784VS.NET IDE : 17. C#, VB.NET, VC++ 단축키 모음
619정성태1/28/200710325IIS : 12. 비스타 버전별 IIS 기능 차이
618정성태1/28/20079565Debug : 8. RuntimeWrappedException 사용 이해
617정성태1/27/200710075TFS : 70. 웹 서비스 구현 없이 TFS 통지 받기파일 다운로드1
616정성태1/27/200710781IIS : 11. Visual SourceSafe 웹 서비스가 비스타 IIS 7에서 지원되지 않는 문제
615정성태1/25/20079922TFS : 69. Workgroup 으로 설치된 TFS 를 Domain 으로 승격하는 방법
614정성태1/25/200710531개발 환경 구성: 71. 현재 프로세스에 로딩된 모듈 중에서 NGen 되지 않은 모듈 검색
613정성태1/25/200710450IIS : 10. IE에 최적화된 성능을 내는 JScript 코드 작성
612정성태1/25/20079558Debug : 7. WinLogon.exe 프로세스 디버깅하는 방법
611정성태1/25/200710016.NET : 52. Team System 단위 테스트에 관한 PDF 문서파일 다운로드1
610정성태1/25/20079988.NET : 51. FxCop 관련 PDF 문서파일 다운로드1
609정성태1/24/20079684.NET : 50. 공급자 독립적인 코드 작성 [2]
608정성태1/23/20079843TFS : 68. TFS Proxy 서버 설치하는 방법
607정성태1/23/20079474이미 제공되는 예외 클래스들에 대한 적절한 사용법 설명
606정성태1/23/200712427TFS : 67. TFS 명령행 인자
605정성태1/23/20078871TFS : 66. 차기 TFS 파워툴 - TFSServerManager / TFSServerMonitor
603정성태1/22/200710004Vista : 30. Property Handler가 필요한 때.
602정성태1/22/200710258IIS : 9. 디렉터리 열람을 위한 HttpModule파일 다운로드1
601정성태1/22/20079334개발 환경 구성: 70. Web Client Software Factory 설치 가이드(비스타)
600정성태1/21/20079828개발 환경 구성: 69. Virtual PC/Server에서의 가상 네트워크 어댑터 추가 방법
599정성태1/21/200710102Vista : 29. UAC 와 보안 데스크탑
... 16  17  18  19  20  21  22  [23]  24  25  26  27  28  29  30  ...