Home » Scripting » Loop and Check process Messages in this topic - RSS
|
1/11/2012 6:24:25 AM
rodrigovecchi
rodrigovecchi
Posts 1
Hello guys,

I need some help to improve a script I created.

I'm new in this world of scripst, and I'm doing a VBS to start a massive deploy of Office 2010.

Script show a message to user close all applications and then the script check if all applications are closed to begin the installation. While script detects process running, show a message to user close the applications.

But, in the script I check process per process, and, if a user open a process after the script had verified it, the script will proceed with the process running.

There's a way to do it better?

This is this part of the script:


'-----------------------------------------------------------------
'Verify running process
'-----------------------------------------------------------------

DIM strComputer,strProcess

strComputer = "." ' local computer

Do

' Check if winword.exe is running
strProcess = "winword.exe"
controle = "0"

if isProcessRunning(strComputer,strProcess) then
controle = "1"
else
controle = "0"
end if

result = MsgBox ("Existem aplicações abertas!" & Chr(10) &_
"Favor fecha-las antes de prosseguir!")

Loop While controle > 0

Do

' Check if excel.exe is running
strProcess = "excel.exe"
controle = "0"

if isProcessRunning(strComputer,strProcess) then
controle = "1"
else
controle = "0"
end if

result = MsgBox ("Existem aplicações abertas!" & Chr(10) &_
"Favor fecha-las antes de prosseguir!")

Loop While controle > 0

Do

' Check if outlook.exe is running
strProcess = "outlook.exe"
controle = "0"

if isProcessRunning(strComputer,strProcess) then
controle = "1"
else
controle = "0"
end if

result = MsgBox ("Existem aplicações abertas!" & Chr(10) &_
"Favor fecha-las antes de prosseguir!")

Loop While controle > 0

Do

' Check if powerpnt.exe is running
strProcess = "powerpnt.exe"
controle = "0"

if isProcessRunning(strComputer,strProcess) then
controle = "1"
else
controle = "0"
end if

result = MsgBox ("Existem aplicações abertas!" & Chr(10) &_
"Favor fecha-las antes de prosseguir!")

Loop While controle > 0

' Function to check if a process is running
function isProcessRunning(byval strComputer,byval strProcessName)

Dim objWMIService, strWMIQuery

strWMIQuery = "Select * from Win32_Process where name like '" & strProcessName & "'"

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")


if objWMIService.ExecQuery(strWMIQuery).Count > 0 then
isProcessRunning = true
else
isProcessRunning = false
end if

end function
_____________________________________________________________________________

Regards,
pages: 1
|

Home » Scripting » Loop and Check process