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


비밀번호

댓글 작성자
 




... 46  [47] 
NoWriterDateCnt.TitleFile(s)
18정성태9/19/200411818HTML SELECT 요소에 OPTION 요소를 채우는 C/C++ 예제파일 다운로드1
17정성태11/14/200510595[정보] Visual Studio 6.0 Samples
16정성태9/5/200411744JAVA 로 구현된 NTLM 구현파일 다운로드1
15정성태9/2/200410406Developing Active Server Components with ATL
14정성태7/20/200410724No-Touch Deployment
13정성태6/30/200410802How to read BLOB from Dataset into buffer?
11정성태2/14/200410696XMLHTTP 에서 반환받은 non-XML 데이터를 보여주는 모듈
10정성태2/14/200413659MSIL 디컴파일러 - .NET Reflector [1]
9정성태1/26/200412027스크립트 디코더파일 다운로드1
159정성태12/23/20059687    답변글 [업데이트]: 스크립트 디코더파일 다운로드1
8정성태1/26/200414604게시물 도배 프로그램 방지
7정성태1/26/200413093Microsoft.XMLHTTP 개체로 XML 이 아닌 다른 데이터 가져오기
6정성태8/6/200311843Three Ways to Inject Your Code into Another Process파일 다운로드1
5정성태7/29/200311971SQL 서버 sa 암호를 잊은 경우, 복구하는 방법파일 다운로드1
4정성태7/25/200313533DiskId32 - 물리하드 디스크 정보파일 다운로드2
12정성태6/11/200410458    답변글 [추가] WMI 로 구하는 방법파일 다운로드1
3정성태7/25/200312098C# 프로그래밍 언어에 추후 추가되는 기능파일 다운로드1
2정성태7/25/200312391INFO: COM+ 1.0의 새로운 기능파일 다운로드1
... 46  [47]