Results 1 to 3 of 3
  1. #1
    DC CS is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2023
    Location
    Vaalpark, South Africa
    Posts
    69

    Check for open WORD processes

    Hi all,
    Is there a way that I can check on a remote server for any open WORD processes as well as the user that has the WORD application open with Access VBA?

    Thanks

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    paste this code into a module then
    usage: KillAllWords


    which scans processes for open word apps.



    Code:
    Option Compare Database
    Option Explicit
    
    
    #If Win64 Then      'Public Dclare PtrSafe Function    ...AS LONGPTR
    Private Declare PtrSafe Function GetCurrentProcessId Lib "kernel32" () As Long
    #Else
    Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
    #End If
    
    
    Public Sub KillAllWords()
     KillMyProcess "Word.exe"
    End Sub
    
    
    Private Sub KillMyProcess(ByVal psProcessName As String)
    Dim oWMI As Object
    Dim oServices As Object
    Dim oSvc
    Dim sSvcName As String
           
    On Error Resume Next
    Set oWMI = GetObject("winmgmts:")
           Set oServices = oWMI.InstancesOf("win32_process")
           For Each oSvc In oServices
               'sSvcName = LCase(Trim(CStr(oSvc.name) & ""))
              'Debug.Print oSvc.name
              
              'If InStr(oSvc.name, psProcessName) > 0 Then
              'Beep
              'End If
              
              If LCase(psProcessName) = LCase(Trim(CStr(oSvc.Name) & "")) Then
                  oSvc.Terminate
               End If
           Next
    End Sub
    
    
    
    
    Function IsProcessRunning(ByVal psProcess As String) As Boolean
        Dim objList As Object
    
    
        Set objList = GetObject("winmgmts:") _
            .ExecQuery("select * from win32_process where name='" & psProcess & "'")
    
    
        If objList.Count > 0 Then
            IsProcessRunning = True
        Else
            IsProcessRunning = False
        End If
    
    
    End Function
    
    
    
    
    Function IsServiceRunning(ByVal psSvc As String) As Boolean
    Dim oWMI As Object
    Dim oServices As Object
    Dim oSvc
    Dim sSvcName As String
    
    
    Set oWMI = GetObject("winmgmts:")
           Set oServices = oWMI.InstancesOf("win32_process")
           For Each oSvc In oServices
              sSvcName = LCase(Trim(CStr(oSvc.Name) & ""))
              'Debug.Print sSvcName
              
              If InStr(oSvc.Name, psSvc) > 0 Then
                IsServiceRunning = True
                Exit Function
              End If
              
              'If LCase(psSvc) = LCase(Trim(CStr(oSvc.name) & "")) Then IsServiceRunning = True
           Next
    End Function

  3. #3
    DC CS is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2023
    Location
    Vaalpark, South Africa
    Posts
    69
    Thanks, but not exactly what I am looking for. I also need the name of the user that has the Word app open on a remote server, as more than 1 user can have the same document open.
    When executing the task manager on the remote server, it looks like this:

    Click image for larger version. 

Name:	Capture.JPG 
Views:	12 
Size:	29.1 KB 
ID:	50606

    I need to close a specific instance of Word, not all instances. For example, I need to close the Word instance where the user = "Dirk".

    Thanks

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 10
    Last Post: 07-03-2022, 02:29 AM
  2. Check If Word Open
    By DMT Dave in forum Access
    Replies: 2
    Last Post: 04-10-2019, 05:49 PM
  3. VBA to pull various processes together
    By buckwheat in forum Access
    Replies: 1
    Last Post: 01-31-2013, 03:31 PM
  4. Replies: 2
    Last Post: 02-26-2010, 08:14 AM
  5. Run 2 Processes in Separate Threads
    By matt_tapia in forum Programming
    Replies: 1
    Last Post: 08-06-2009, 12:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums