Microsoft MVP성태의 닷넷 이야기
개발환경 구성 : 24. Smart Start and Stop Service in VS.NET Build [링크 복사], [링크+제목 복사],
조회: 14039
글쓴 사람
정성태 (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)
92정성태5/5/200511881XP SP2 방화벽에 대한 내용을 정라한 블로그 소개
91정성태5/5/200512452구글 맵 ( Microsoft MapPoint 수준 )
90정성태4/21/200512331Virtual Server 2005 SP1 beta
89정성태4/1/20051234064bit Windows 2003(x64) , 32bit Windows 2003 SP1 배포
88정성태3/31/200511701HTML to XHTML
87정성태3/31/200512704NewSID : Ghost / VPC 등으로 복제된 컴퓨터의 SID 를 변경
86정성태3/31/200512086Push and Run .NET Code on Remote Machine
84정성태3/25/200511226NET Framework v2 Beta 2 Obsolete APIs
83정성태3/25/200511740서버 운영체제 라이센싱 및 지원 비용 비교 보고서파일 다운로드1
80정성태3/22/200512925VS.NET 2005 가격정책
82정성태3/24/200512326    답변글 VS.NET 2005, SQL 2005 출시 연기
78정성태3/21/200513069ASP.NET
77정성태3/13/200512705Virtual Server : COM 개체로 다루기
75정성태3/9/200511869C# to Visual Basic.NET Translation Tool
79정성태3/22/200512379    답변글 PHP ompiler for .NET Framework
81정성태3/23/200511898    답변글 Microsoft Java Language Conversion Assistant 3.0 beta
85정성태3/27/200512383    답변글 Convert VBA Code to Visual Basic .NET When Migrating to Visual Studio 2005 Tools for Office
74정성태3/9/200511902Internet Explorer 7 곧 출시 예정
73정성태3/4/200512428Developing Solutions with Microsoft InfoPath - Companion Content
72정성태3/4/200512529레지스트리 Control Set 과 CurrentControlSet 의 의미.
71정성태3/4/200511349환경 변수를 등록 후에 시스템에 알리는 방법
70정성태3/4/200512721.NET Tools: Ten Must-Have Tools Every Developer Should Download Now [1]
69정성태3/3/200511390SQL Server 2005 - beta 3
67정성태4/1/200512895스마트 클라이언트 외부 자료 링크
66정성태2/19/200511576오라클 DB 를 Microsoft SQL Server 로 마이그레이션 하기파일 다운로드1
65정성태2/15/200512435Office 2003: XML Reference Schemas
... 31  32  33  34  35  36  37  38  39  40  41  42  43  [44]  45  ...