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


비밀번호

댓글 작성자
 




... 31  [32]  33  34  35  36  37  38  39  40  41  42  43  44  45  ...
NoWriterDateCnt.TitleFile(s)
398정성태8/12/200614467Debug : 4. SOS로 Managed 객체의 크기 구하는 방법
397정성태8/12/200614890IIS - 4. Extending the TreeView in IIS 7 in Windows Vista파일 다운로드1
396정성태8/11/200614234TFS : 21. Process Template Schemas Download
395정성태8/10/200614033개발환경 구성 : 21. Introduction to Visual Studio 2005 Team System Guide
394정성태8/10/200616233개발환경 구성 : 20. VHD 파일 크기 줄이기파일 다운로드1
392정성태8/9/200614052개발환경 구성 : 19. 몇 가지 유용한 ASP.NET 아티클 링크
393정성태8/10/200613844    답변글 개발환경 구성 : 19.1 몇 가지 유용한 ASP.NET 아티클 링크
391정성태8/9/200613507개발환경 구성 : 18. CardSpace 구현 예제파일 다운로드1
390정성태8/9/200613192개발환경 구성 : 17. 주의해야 할 프로그래밍 패턴
389정성태8/8/200618606C# event 와 delegate 의 차이?파일 다운로드1
388정성태8/7/200613116.NET : 10. C# 3.0 소식
387정성태10/20/200613941Vista : 7. System Services change in Windows Vista
385정성태10/20/200614533.NET 3.0 : 2. WCF Service with .asmx extentions 파일 다운로드1
384정성태10/20/200614292Vista : 6. Programming the Windows Vista Event Log [1]
383정성태10/20/200614327Vista : 5. MSDE Will Not Be Supported on Vista
382정성태10/20/200616555Vista : 4. IE 7+ 이름 변경
381정성태8/7/200613052개발환경 구성 : 16. Windows RSS API 사용법파일 다운로드1
380정성태8/4/200613055개발환경 구성 : 15. Windows Command Line Auto Completion
379정성태8/1/200612731.NET : 9. Self compiling scripts for .NET languages: C#, VB.NET and JScript.NET파일 다운로드1
378정성태8/1/200613133개발환경 구성 : 14. [사용설명서] SQL Server Everywhere 버전
377정성태7/31/200613316개발환경 구성 : 13. 도움말 생성기 - Sandcastle
386정성태8/7/200613023    답변글 개발환경 구성 : 13.1 Sandcastle 사용예파일 다운로드1
376정성태7/25/200612632TFS : 20. TFS 사용 현황 사례
375정성태7/25/200612931개발환경 구성 : 12. [CodePlex] 신규 프로젝트 - TFS File Sync
374정성태7/24/200614800Reflection 의 속도 향상을 원한다면?
373정성태7/23/200614090.NET : 8. The ADO.NET Entity Framework Overview [2]
... 31  [32]  33  34  35  36  37  38  39  40  41  42  43  44  45  ...