Microsoft MVP성태의 닷넷 이야기
개발환경 구성 : 24. Smart Start and Stop Service in VS.NET Build [링크 복사], [링크+제목 복사],
조회: 14062
글쓴 사람
정성태 (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)
346정성태6/29/200612212Debug : 1. How to build Mdbg apps파일 다운로드1
344정성태10/20/200614933Vista : 3. Vista에서 제거되는 DHTML Editing Control - 두 번째 소식
345정성태10/20/200613601    답변글 Vista : 3.1 [현상 1] Vista 에서 OWA 접근
351정성태10/20/200616817    답변글 Vista : 3.2 Vista에서 문제되는 웹 사이트
352정성태10/20/200613995    답변글 Vista : 3.3 Vista 관련 조각 코드파일 다운로드1
343정성태6/26/200612694TFS : 10. TFS Bug Snapper v1.0 Released
342정성태6/26/200612006TFS : 9. TFS Notification Web Services - Project Template 1.1 available
341정성태6/25/200612511.NET : 7. VCPROJ - Shared Source Common Language Infrastructure 2.0 Release파일 다운로드1
340정성태6/25/200611902개발환경 구성 : 7. XSLT on the fly.
339정성태6/25/200612277.NET : 6. 무료 - ByesRoad.NetSuit Library
337정성태10/20/200616669Vista : 2. Credential Provider Samples파일 다운로드1
336정성태6/23/200611974.NET : 5. BLINQ using LINQ
335정성태6/23/200612595개발환경 구성 : 6. MSBuild or Team Build Tasks in the Community
334정성태6/26/200612095TFS : 8. Customizing MSF Process Guidance
333정성태6/21/200612319VS.NET IDE : 6. The Visual Studio Hosting Process - VSHost.exe
332정성태6/21/200612317TFS : 7. Team Foundation Power Toys
331정성태6/21/200612047Debug: CardSpaces Crash 를 해결해 가는 디버깅 과정
330정성태10/20/200613467Vista : 1. New API - 스레드 대기 상태를 확인하는 방법 제공
329정성태6/21/200612215.NET : 4. Tech-Ed 2006 - WebCast 자료
328정성태6/23/200613110개발환경 구성 : 5. Robocopy GUI
327정성태6/18/200613805.NET : 3. Open XML을 다루는 코드 스니핏 [1]
326정성태6/18/200613101개발환경 구성 : 4. COM+ 서비스에서 인증서 사용.
325정성태6/17/200613038STL.NET
324정성태6/17/200612816개발환경 구성 : 3. Signed versions of the power toys available on MS Downloads
323정성태6/17/200613342개발환경 구성 : 2. the sandbox projects
322정성태6/17/200614070TFS : 6. TFS 데이터베이스 백업파일 다운로드1
... 31  32  33  [34]  35  36  37  38  39  40  41  42  43  44  45  ...