vbaoutlookskype-for-businessuser32winscard

Determine if the computer is locked


I have a macro that send me a text from outlook when a meeting notification pops up. I would like to figure out a way to make that macro only run if I am not at my computer. I have looked for a way to pull my status from Skype for Business, determine if the PC is locked or not, and see if a smart card is inserted. All without much luck. Looking for a simple solution that works in VBA.


Solution

  • I used the code from here Determine if application is running with Excel

    Function IsProcessRunning(process As String)
        Dim objList As Object
    
        Set objList = GetObject("winmgmts:") _
            .ExecQuery("select * from win32_process where name='" & process & "'")
    
        If objList.Count > 0 Then
            IsProcessRunning = True
        Else
            IsProcessRunning = False
        End If
    
    End Function
    

    Based on the answer here In Python 3, how can I tell if Windows is locked?

    I called

    IsProcessRunning("LogonUI.exe")
    

    and it seems to work.