Microsoft MVP성태의 닷넷 이야기
개발환경 구성 : 24. Smart Start and Stop Service in VS.NET Build [링크 복사], [링크+제목 복사]
조회: 11108
글쓴 사람
정성태 (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)
450정성태9/28/20069538.NET : 16. ADO.NET vNext Entity Data Model Designer Prototype, CTP
449정성태9/28/200610468TFS : 37. Team Foundation Server and Basic Authentication
448정성태9/28/200610019TFS : 36. Moving the Team Foundation Server Data Warehouse to a Separate Server
447정성태10/20/200610155Vista : 10. ASLR이 적용된 Vista
446정성태9/26/20069935개발환경 구성 : 31. Profiling Tool for .NET Developers
445정성태10/20/20069603Windows 2008 : 2. LHS Feature Of The Week #2 - Remote Differential Compression
444정성태10/20/200610165Windows 2008 : 1. LHS Feature Of The Week #1 - Transactional NTFS
443정성태9/23/200610048개발환경 구성 : 30. Tip/Trick: Optimizing ASP.NET 2.0 Web Project Build Performance with VS 2005
442정성태9/28/200610619TFS : 35. 설치 설명서 / 관리자 가이드 도움말 업데이트
441정성태9/21/200611099개발환경 구성 : 29. SQL Server Spec 비교
440정성태10/20/200610497.NET 3.0 : 3. WCF Workshops updated to Release Candidate 1
439정성태9/20/200610503개발환경 구성 : 28. Caml Viewer 2007 : released on Codeplex
438정성태9/20/200610274개발환경 구성 : 27. Enterprise Smart Card Deployment in the Microsoft® Windows® Smart Card Framework
437정성태9/19/200610210TFS : 34. Getting Started with TFS Integrator 파일 다운로드2
434정성태9/20/200610909개발환경 구성 : 26. Developing Web Applications on Windows Vista with Visual Studio 2005
433정성태10/20/200610394Vista : 9. Next Generation TCP/IP Stack
432정성태9/16/200610252TFS : 33. Now Available: Teamprise V2 Preview 2
431정성태9/16/20069898개발환경 구성 : 25. Announcing the Web Client Software Factory
430정성태9/15/200610245.NET : 15. ASP.NET 2.0 - A Preview of Web LINQ - BLINQ
429정성태9/15/20069828The True Cost of .NET Exceptions
428정성태9/15/200611617.NET : 14. IronPython 예제들
427정성태9/14/200611108개발환경 구성 : 24. Smart Start and Stop Service in VS.NET Build
426정성태9/13/200610551TFS : 32. Team Foundation Server Language Change Package
425정성태9/12/200610380TFS : 31. Team Foundation Administrator's Guide (TFSAdmin.chm)
424정성태9/12/200611039Visual C++ : 2. Managed Debugger Expression Evaluator - mcee_mc.dat
422정성태9/8/200610925.NET : 13. An Introduction to LINQ
... 16  17  18  19  20  21  22  23  24  25  26  27  28  29  [30]  ...