Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

detecting if Word is active with VBScript

Status
Not open for further replies.

pietersj

Programmer
Jul 11, 2001
8
BE
Can anybody tell me if it's possible to detect if Word is active on a client PC.
I can start Word using the Word type library - as a new task - create a new document ,... but i want detect if there's already an active instance of Word.
 
Hello, pietersj.

May try the script hereinbelow, see if it answers your query.

Get the idea behind and you can therefore modify it to suit your other uses. It is not limited to detect MS Words. Just change the sPattern to other representative applications and it'll run the same.

regards - tsuji

'-----------------------/tsuji/---------
Option Explicit

Dim sPattern, oWMI, Instances, arrayProc, oProc, sProc, separator, i
sPattern = "Winword"
separator = space(1)
Set oWMI = GetObject("winmgmts:") 'for local
sProc = separator : Instances = 0 : sPattern = trim(sPattern)
For Each oProc in oWMI.InstancesOf("Win32_Process")
sProc = sProc & oProc.Description & separator
Next

arrayProc = Split(trim(sProc),separator)
For i = 0 to UBound(arrayProc)
If InStr(1,UCase(trim(arrayProc(i))),UCase(sPattern),1) <> 0 Then
Instances = Instances + 1
End If
Next

If Instances <> 0 Then
MsgBox &quot;The process represented by the pattern [ &quot; & sPattern & _
&quot; ] is running on the local in [ &quot; & cstr(Instances) & &quot; ] instance(s).&quot;
Else
MsgBox &quot;The process represented by the pattern [ &quot; & sPattern & _
&quot; ] is not running on the local.&quot;
End If

Set oWMI = Nothing
WScript.Quit
'-----------------------/tsuji/---------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top