성태의 닷넷 이야기
홈 주인
모아 놓은 자료
프로그래밍
질문/답변
사용자 관리
사용자
메뉴
아티클
외부 아티클
유용한 코드
온라인 기능
MathJax 입력기
최근 덧글
[정성태] Roll A Lisp In C - Reading ; https...
[정성태] Java - How to use the Foreign Funct...
[정성태] 제가 큰 실수를 했군요. ^^; Delegate를 통한 Bein...
[정성태] Working with Rust Libraries from C#...
[정성태] Detecting blocking calls using asyn...
[정성태] 아쉽게도, 커뮤니티는 아니고 개인 블로그입니다. ^^
[정성태] 질문이 잘 이해가 안 됩니다. 우선, 해당 소스코드에서 ILis...
[양승조
] var대신 dinamic으로 선언해서 해결은 했습니다. 맞는 해...
[양승조
] 또 막혔습니다. ㅠㅠ var list = props[i].Ge...
[양승조
] 아. 감사합니다. 어제는 안됐던것 같은데....정신을 차려야겠네...
글쓰기
제목
이름
암호
전자우편
HTML
홈페이지
유형
닷넷
.NET 3.0
.NET 3.5
.NET 4.0
VC++
개발 환경 구성
제품 소개
VS.NET IDE
Vista
Windows 7
Windows 8
Windows 서버
Team Foundation Server
IIS
디버깅 기술
Win32
64비트
오피스
웹
기타
Phone
부모글 보이기/감추기
내용
Smart Start and Stop Service in VS.NET Build<br /> ; <a target="_blank" href="http://blogs.msdn.com/irenak/archive/2006/09/13/752075.aspx">http://blogs.msdn.com/irenak/archive/2006/09/13/752075.aspx</a><br /> <br /> NT 서비스 프로그램에 대한 빌드를 할 때, 빌드 이벤트로 넣어두면 좋겠지요. ^^ <hr /> <P class=MsoNormal style="MARGIN: 0in 0in 0pt">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.<SPAN style="mso-spacerun: yes"> </SPAN>The script below, courtesy of Scott Jennings, is a way to stop and start service, if it’s installed and is running/stopped correspondingly.<SPAN style="mso-spacerun: yes"> </SPAN>All that remains to do it to add the script invocation code to pre-build and post-build event command lines in Visual Studio.<BR style="mso-special-character: line-break"><BR style="mso-special-character: line-break"></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana">' Usage:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana">'<SPAN style="mso-spacerun: yes"> </SPAN>start /w wscript "<path>\ServiceHelper.vbs" <start|stop> <servicename><o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana">' Example:<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana">'<SPAN style="mso-spacerun: yes"> </SPAN>start /w wscript "C:\Projects\XYZ\ServiceHelper.vbs" start myservice<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p> </o:p></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana">Dim WMIService<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana">Dim Services<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana">Dim Service<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana">Dim action<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana">Dim result<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana"><o:p> </o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana">If Wscript.Arguments.Count <> 2 Then<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana"><SPAN style="mso-tab-count: 1"> </SPAN>Wscript.Echo "Usage: ServiceHelper.vbs start|stop ServiceName"<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana"><SPAN style="mso-tab-count: 1"> </SPAN>Wscript.Quit 1<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana">End If<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana"><o:p> </o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana">Set WMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana"><o:p> </o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana">Set Services = WMIService.ExecQuery("Select * from Win32_Service where Name = '" + Wscript.Arguments(1) + "'")<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana"><o:p> </o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana">If Services.Count > 1 Then<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana"><SPAN style="mso-tab-count: 1"> </SPAN>Wscript.Echo "More than one matching service"<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana"><SPAN style="mso-tab-count: 1"> </SPAN>Wscript.Quit 1<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana">ElseIf Services.Count = 1 Then<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana"><SPAN style="mso-spacerun: yes"> </SPAN>action = Wscript.Arguments(0)<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana"><o:p> </o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana"><SPAN style="mso-spacerun: yes"> </SPAN>For Each Service In Services<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana"><SPAN style="mso-spacerun: yes"> </SPAN>If action = "start" AND Service.State <> "Running" Then<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana"><SPAN style="mso-spacerun: yes"> </SPAN>result = Service.StartService()<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana"><SPAN style="mso-spacerun: yes"> </SPAN>ElseIf action = "stop" AND Service.State <> "Stopped" Then<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana"><SPAN style="mso-spacerun: yes"> </SPAN>result = Service.StopService()<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana"><SPAN style="mso-spacerun: yes"> </SPAN>End If<SPAN style="mso-spacerun: yes"> </SPAN><o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana"><SPAN style="mso-spacerun: yes"> </SPAN>Next<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana"><o:p> </o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana"><SPAN style="mso-spacerun: yes"> </SPAN>Wscript.Quit(result)<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana">Else<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana"><SPAN style="mso-spacerun: yes"> </SPAN>Wscript.Echo "No such service found"<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana"><SPAN style="mso-spacerun: yes"> </SPAN>Wscript.Quit 1<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana">End If<o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p> </o:p></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><I style="mso-bidi-font-style: normal">Special thanks to Scott Jennings who created this solution!<o:p></o:p></I></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p> </o:p></P>
첨부파일
스팸 방지용 인증 번호
5579
(왼쪽의 숫자를 입력해야 합니다.)