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


비밀번호

댓글 작성자
 




1  2  3  4  5  6  7  8  [9]  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
975정성태10/9/200810703.NET : 88. ClickOnce에서 .application 파일을 다운로드 하려고 할 때.
974정성태10/8/200810721TFS : 168. MSBuild Extension Pack
973정성태10/5/200812393.NET 3.5 : 42. WPF - Web Browser 및 Splash Control 추가
972정성태10/2/200810678TFS : 167. TFS Power Tools 다음 버전 소개
971정성태9/22/200810994TFS : 166. Index cards and Team System
970정성태9/16/200810976Vista : 53. 설치 디스크를 USB 로 만들기
968정성태9/11/200810590XML Conformance Level 에 Fragment 값이 쓰이는 경우.
967정성태9/8/200810715.NET : 87. CertEnroll 개체를 이용한 인증서 요청/반환/설치
966정성태9/2/200810773.NET : 86. .NET Framework 3.5 SP1 소스 코드 공개
965정성태9/2/200811712Vista : 52. SPI(Stateful Packet Inspection) 옵션 제거
964정성태8/18/200812722.NET 3.0 : 24. WPF DataGrid
969정성태9/16/200811001    답변글 .NET 3.0 : 24.1 Editing Tabular Data in WPF - Building a WPF Grid
963정성태7/25/200811786.NET : 85. VPL(Visual Programming Language)를 아세요?
962정성태7/24/200810846TFS : 165. WorkItem 에 대해 Full Text 검색
961정성태7/20/200810794.NET : 84. WCSF Application Architecture
960정성태7/14/200810620.NET : 83. Non Paged CLR Host
959정성태7/7/200811163.NET : 82. Composite Application Guidance for WPF
958정성태7/7/200812316.NET : 81. C# - 왜 모든 함수호출에서 callvirt 를 사용할까?
957정성태6/30/200811288GUID
956정성태6/27/200810801TFS : 164. 팀 프로젝트 간 WorkItem 이동 방법
955정성태6/26/200811324TFS : 163. 삭제된 항목을 소스 컨트롤 탐색기에서 보이도록 하는 방법
954정성태6/20/200810955Debug : 37. IDE 디자인 모드에서의 디버깅 기법
953정성태6/10/200811806.NET : 80. Unity Application Block 소개(?) [1]
952정성태4/28/200811072.NET : 79. IconHandler 2.0
951정성태4/28/200811486SDK : 14. STA / MTA 기원
950정성태4/24/200810585.NET : 78. Ajax View
1  2  3  4  5  6  7  8  [9]  10  11  12  13  14  15  ...