[VBS]파라미터로 받아 실행되는 응용 프로그램의 실행 상태 확인 Etc.2010. 10. 8. 15:05
Notepad.exe APP1
Notepad.exe APP2
셈플은 DB 테이블에서 | (파이프)로 구분된 APP1|APP2를 분리해 검색
와 같은 형태로 실행되는 응용 프로그램의 실행 상태를 파라미터(APP1, APP2) 기준으로 상태를 표시
VBS VBScript
sHostProcess = "notepad.exe"
Set dbcon = CreateObject("Adodb.connection")
sCon = "Provider=sqloledb;Data Source = 10.10.10.10;User ID=sa;Password=P@ssw0rd;Initial Catalog=DBName"
dbcon.open sCon
sSQL = "select * from table1"
Set Result = dbcon.execute(sSQL)
Do While not Result.eof
sApplication = sApplication & Trim(Result(0)) & "|"
Result.movenext
Loop
Set Result = Nothing
dbcon.close
sApplication = LEFT(sApplication, LEN(sApplication) - 1)
arrApplication = Split(sApplication,"|")
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colHostProcess = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = '" & sHostProcess & "'")
If colHostProcess.Count = 0 Then
WScript.Echo "Host rocess is not running."
Set objWMIService = Nothing
WScript.Quit
End If
sStatus = "Good"
sMessage = ""
WScript.Echo "Host process " & sHostProcess
For Each App in arrApplication
intState = GetAppState(App)
If intState = 1 Then
WScript.Echo App & " Running"
Else WScript.Echo App & " Not running"
sMessage = sMessage & App & " is not running" & " | "
sStatus = "Bad"
End If
Next
sMessage = LEFT(sMessage, LEN(sMessage) - 3)
WScript.Echo "Status is " & sStatus
WScript.Echo "Message is " & sMessage
Set objWMIService = Nothing
WScript.Quit
Function GetAppState(sAppName)
For Each Item in colHostProcess
arrCommandLine = Split(Item.CommandLine," ")
For Each arrItem in arrCommandLine
If Instr(UCASE(arrItem), UCASE(sAppName)) Then
GetAppState = 1
End If
Next
Next
End Function