Microsoft MVP성태의 닷넷 이야기
개발환경 구성 : 24. Smart Start and Stop Service in VS.NET Build [링크 복사], [링크+제목 복사],
조회: 11148
글쓴 사람
정성태 (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)
525정성태11/14/200610413Vista : 14. .NET 개발자들을 위한 Vista 기능 소개
524정성태11/13/20069947TFS : 55. Annotate 소개
523정성태11/13/200611519.NET 3.0 : 7. WPF - EXE 유형의 프로젝트를 XBAP 유형으로 변경
522정성태11/12/200611073.NET : 33. SynchronizationContext 에 대해서.
521정성태11/12/20069678SDK : 7. Sessions, Window Stations, Desktops
520정성태11/12/200611217Vista : 13. LLTD(Link Layer Topology Discovery)가 뭘까요?
519정성태11/12/20069691Vista : 12. Network Location Type - Public, Private, Domain - 에 대한 설명.
518정성태11/12/20069506개발 환경 구성: 53. Sandcastle - 일반적인 HTML 파일 이름 생성
517정성태11/11/200610299.NET : 32. Enterprise Library - 예외 처리 가이드 (PPT 및 소스 코드) [2]파일 다운로드1
516정성태11/10/20069194개발 환경 구성: 52. Vista - 원격 터미널 클라이언트에서 다중 모니터 지원
515정성태11/8/200610161SDK : 6. 패치 툴 소개 ( mspatcha, mspatchc )파일 다운로드1
514정성태11/8/20069932.NET : 31. MSN Messenger 연동 라이브러리
513정성태11/8/200611354Visual C++ : 5. Browser Helper Object 제작 방법
512정성태11/8/200611518SDK : 5. Tiny PE - 가장 작은 PE 파일 제작파일 다운로드1
511정성태11/8/200610589개발 환경 구성: 51. Extended Validation (EV) SSL 인증서 소식 [1]
510정성태11/7/200610337VS.NET IDE : 13. Guidance Automation Toolkit and Domain-Specific Language Tools for Visual Studio 2005: Integration Scenarios
509정성태11/7/20069871.NET 3.0 : 6. ADO.NET Samples for Visual Studio Code Name “Orcas” - October CTP
508정성태11/6/20069660TFS : 54. 새로운 TFS 리포트 생성
507정성태11/5/20069448.NET : 30. LINQ 관련 자료
506정성태11/5/20069741.NET : 29. .NET Fusion API
505정성태11/4/20069560.NET : 28. The .NET Developer's Guide to Identity
504정성태11/4/20069763.NET : 27. ASP.NET 2.0 Resource-Provider 모델 확장
503정성태11/4/20069742TFS : 53. VSTS 관련 자료 링크 모음
502정성태11/4/20069515TFS : 52. Data-Tier Server 미러링
501정성태11/3/20069728TFS : 51. TFS 증분 빌드 환경 설정
500정성태11/2/20069593TFS : 50. TfsAlert 0.3.0.0 릴리스
... 16  17  18  19  20  21  22  23  24  25  26  [27]  28  29  30  ...