개발
WshShell Object((Windows Script Host Shell Object) VBScript 에서 Shell 실행 방법
날아가는 된장잠자리
2010. 9. 6. 13:39
ASP 개발자라면 VBS를 활용한 데몬 작업을 적지 않게 하게 되는데
가끔 VBS에서 Shell 커맨드를 실행하고자 할 때 어찌해야 할 지 모르는 경우가 있다.
그럴 경우, 아래를 참조하면 된다.
아래 기본적인 WshShell Object에 대한 프로퍼티와 메서드에 설명과
Exec 메서드와 Run 메서드에 대한 설명이 있다.
추가로, 실행 상태 및 오류사항을 확인하기 위하여는 Status, StdErr 프로퍼티를 참고하면 된다.
Properties
Example(Run Method)
가끔 VBS에서 Shell 커맨드를 실행하고자 할 때 어찌해야 할 지 모르는 경우가 있다.
그럴 경우, 아래를 참조하면 된다.
아래 기본적인 WshShell Object에 대한 프로퍼티와 메서드에 설명과
Exec 메서드와 Run 메서드에 대한 설명이 있다.
추가로, 실행 상태 및 오류사항을 확인하기 위하여는 Status, StdErr 프로퍼티를 참고하면 된다.
Properties
- CurrentDirectory Property
- Environment Property
- SpecialFolders Property
Methods
- AppActivate Method
- CreateShortcut Method
- Exec Method
- ExpandEnvironmentStrings Method
- LogEvent Method
- Popup Method
- RegDelete Method
- RegRead Method
- RegWrite Method
- Run Method
- SendKeys Method
Dim WshShell, oExec Set WshShell = CreateObject("WScript.Shell") Set oExec = WshShell.Exec("calc") Do While oExec.Status = 0 WScript.Sleep 100 Loop WScript.Echo oExec.Status
Example(Run Method)
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "%windir%\notepad " & WScript.ScriptFullName
반환값없이 단독 실행시에는 괄호로 묶지 않는다.
Set WshShell = WScript.CreateObject("WScript.Shell") Return = WshShell.Run("notepad " & WScript.ScriptFullName, 1, true)
* 비교 : Run 과 Exec
'=> Run 은 실행만 하지만, Exec는 실행과 동시에 개체(object)를 생성한다.
' 따라서 Exec를 통한 실행은 생성된 개체를 이용한 후속 작업이 용이하다.