Microsoft MVP성태의 닷넷 이야기
개발환경 구성 : 24. Smart Start and Stop Service in VS.NET Build [링크 복사], [링크+제목 복사],
조회: 11136
글쓴 사람
정성태 (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)
599정성태1/21/200710099Vista : 29. UAC 와 보안 데스크탑
598정성태1/21/20079370VS.NET IDE : 16. Orcas 2월 CTP 소식 - Sapphire 프로젝트
604정성태1/23/20079394    답변글 VS.NET IDE : 16.1 Sapphire가 결합된 Orcas 미리 보기
597정성태1/24/20079201.NET : 49. Enterprise Library 3.0 2007년 1월 CTP
596정성태1/20/20079908Visual C++ : 7. ATL Server 공유 소스 프로젝트로 공개(계획)
595정성태1/19/200711320Vista : 28. Windows Eventing 6.0과 관련된 토픽 모음 [2]
593정성태1/18/200710129개발 환경 구성: 68. Dotfuscator Stack trace decoding tool
592정성태1/18/200711054IIS : 8. 기본 문서 동작 방식
591정성태1/18/20079986.NET 3.5 : 2. Orcas CTP에서 소개되는 새로운 암호화 관련 클래스
590정성태1/17/200710249.NET 3.5 : 1. Orcas Jan CTP 에서 간단한 Linq 프로그램 시작
589정성태1/17/200710055Visual C++ : 6. VC 8.0 런타임 설치 여부
588정성태1/16/20079758Vista : 27. 비스타 용 응용 프로그램 개발 관련 문서
587정성태1/16/200710126Vista : 26. 시작 프로그램에 등록되는 응용 프로그램 마이그레이션
586정성태1/16/20079849TFS : 65. Areas, Iterations, and Subscriptions
585정성태1/16/20079515.NET : 48. Java 와 .NET 의 보안 측면을 비교한 문서 [2]
584정성태1/15/20079849.NET : 47. PInvoke 함수에 대한 적절한 보안 적용
583정성태1/10/20079414Debug : 6. MDbg 관련 자료 링크 모음
582정성태1/10/20079267.NET 3.0 : 11. Windows CardSpace Hads on Lab
581정성태1/10/20079311.NET : 46. Validation Application Block (Enterprise Library 3.0)
594정성태1/18/20079708    답변글 EntLib 3.0 1월 CTP - Validation Application Block
580정성태1/9/20079835TFS : 64. 명령행에서 프록시 서버 지정
579정성태1/9/20079520TFS : 63. Area 의 정의
578정성태1/8/200710075Vista : 25. 비스타 멀티 부트
577정성태1/5/20079738VS.NET IDE : 15. 사용팁 몇 가지
576정성태1/5/20079560.NET : 45. internal 접근자보다 더 안전하게 보호하는 방법
575정성태1/4/20079886TFS : 62. Doing an Incremental Get in Team Build
... 16  17  18  19  20  21  22  23  [24]  25  26  27  28  29  30  ...