确定计算机是否被锁定

问题描述 投票:0回答:1

我有一个宏,可在弹出会议通知时从Outlook向我发送文本。我想找出一种方法,使该宏仅在不使用计算机时才运行。我一直在寻找一种从Skype for Business中获取状态,确定PC是否已锁定以及是否插入智能卡的方法。一切都没有太大的运气。寻找一种可以在VBA中使用的简单解决方案。

vba outlook skype-for-business user32 winscard
1个回答
0
投票

也许这有什么帮助

Option Explicit

Private Declare Function SwitchDesktop Lib "User32" (ByVal hDesktop As Long) As Long
Private Declare Function OpenDesktop Lib "User32" Alias "OpenDesktopA" (ByVal lpszDesktop As String, ByVal dwFlags As Long, ByVal fInherit As Long, ByVal dwDesiredAccess As Long) As Long
Private Declare Function CloseDesktop Lib "User32" (ByVal hDesktop As Long) As Long
#If VBA7 Then
   Declare PtrSafe Function LockWorkStation Lib "user32.dll" () As Long
#Else
   Declare Function LockWorkStation Lib "user32.dll" () As Long
#End If


Private Const DESKTOP_SWITCHDESKTOP As Long = &H100


Function desktopLocked() As String
Dim p_lngHwnd As Long
Dim p_lngRtn As Long
Dim p_lngErr As Long
Dim System As String

    p_lngHwnd = OpenDesktop(lpszDesktop:="Default", dwFlags:=0, fInherit:=False, dwDesiredAccess:=DESKTOP_SWITCHDESKTOP)

    If p_lngHwnd = 0 Then
        System = "Error"
    Else
        p_lngRtn = SwitchDesktop(hDesktop:=p_lngHwnd)
        p_lngErr = Err.LastDllError

        If p_lngRtn = 0 Then
            If p_lngErr = 0 Then
                System = "Locked"
            Else
                System = "Error"
            End If
        Else
            System = "Unlocked"
        End If

        p_lngHwnd = CloseDesktop(p_lngHwnd)
    End If
    desktopLocked = System
End Function
© www.soinside.com 2019 - 2024. All rights reserved.