Results 1 to 6 of 6

Thread: Determine if WinWord.Exe is running

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2015
    Posts
    2

    Question Determine if WinWord.Exe is running

    Hello,
    Newbee here and somewhat inexperienced with VBScript so here goes...

    I have a need to make sure that there aren't any word applications running when I run a script. Sometimes, Word will not have a file open but it will be there in the taskbar (application is running but no file). Therefore, I need to kill this word application so I can open one with the script.

    Guy Thomas was kind enough to provide this sub-routine to kill the running processes. It works quite well.

    But, in my script, I'm posting a message box that notifies the user that the system is going to close all Word applications. This requires and OK or Cancel response from the user.

    I'd like to prevent this message from popping-up if there aren't any word processes running. My problem is that I don't know how to determine that there is at least one instance running. If I can do that, then I can put an IF statement and control when the user prompt pops up.

    So, how would I illicit a response from the system as to whether or not there are any WinWord.Exe processes running?



    Public Sub Word_Grim_Reaper()
    ' ProcessKillLocal.vbs
    ' Sample VBScript to kill a program
    ' Author Guy Thomas http://computerperformance.co.uk/
    ' Version 2.7 - December 2010
    ' ------------------------ -------------------------------'

    Dim objWMIService, objProcess, colProcess
    Dim strComputer, strProcessKill
    strComputer = "."
    strProcessKill = "'WinWord.Exe'"

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

    Set colProcess = objWMIService.ExecQuery _
    ("Select * from Win32_Process Where Name = " & strProcessKill )
    For Each objProcess in colProcess
    objProcess.Terminate()
    Next


    End Sub

    Thank you

  2. #2
    Hyperactive Member
    Join Date
    Oct 2013
    Posts
    389

    Re: Determine if WinWord.Exe is running

    Hey,

    VScript <> VB6

    Regardless, if you just need a script to close a task just Shell window's taskkill command line.
    e.g close notepad.exe on a local machine

    Code:
    taskkill /im notepad.exe
    for more info and parameters: http://technet.microsoft.com/en-us/l.../bb491009.aspx

    a small search to figure out if a process is running via VB, got me to this thread:
    http://www.vbforums.com/showthread.p...unning-Process
    you cna find at least 3 different ways to do so in that thread alone.

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Determine if WinWord.Exe is running

    I think you mean elicit not "illicit" above.

    Not only isn't this a scripter's forum, what you are trying to do is frought with woes. Office applications are not meant to be run unattended from any script, service, etc. See Considerations for server-side Automation of Office which also applies to any kind of batch activity such as a scheduled task.

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2015
    Posts
    2

    Re: Determine if WinWord.Exe is running

    Yes, elicit is the word I was looking for, thank you.

    I'm sorry about the misuse of the VB Forum. For some reason, I assumed that VB and VB Script were so closely related that I could get some help on this forum for the problems I'm experiencing. I came across this forum because of other posts that dealt with problems similar to mine. Apparently, I can get some help.

    Stum, the link you found matches what I was looking for and it even looks like VnTalk (the creator of that thread) has the same code that I'm using.

    I think the code:

    If colProcesses.Count Then
    isRunning = True
    Else
    isRunning = False
    End If

    Thank you!



    Quote Originally Posted by stum View Post
    Hey,

    VScript <> VB6

    Regardless, if you just need a script to close a task just Shell window's taskkill command line.
    e.g close notepad.exe on a local machine

    Code:
    taskkill /im notepad.exe
    for more info and parameters: http://technet.microsoft.com/en-us/l.../bb491009.aspx

    a small search to figure out if a process is running via VB, got me to this thread:
    http://www.vbforums.com/showthread.p...unning-Process
    you cna find at least 3 different ways to do so in that thread alone.

  5. #5
    Hyperactive Member
    Join Date
    Oct 2013
    Posts
    389

    Re: Determine if WinWord.Exe is running

    For future searches, if anyone still needs to enumerate through running processes and find out if one process is currently running:

    Code:
    Dim Process As Object
    For Each Process In GetObject("winmgmts:").ExecQuery("Select * from Win32_Process")
        If Process.Caption = "WINWORD.EXE" Then
            Msgbox ("Word is Running !")
        End If
    Next
    credit on this snippet goes to dee-u *

  6. #6
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Determine if WinWord.Exe is running

    VBScript:
    Code:
    msgbox wordIsRunning
    
    function wordIsRunning
        dim wdApp
        on error resume next
        set wdApp = GetObject(, "Word.Application")
        wordIsRunning = (err.Number = 0)
        set wdApp = nothing
    end function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width