2017-09-13 51 views
0

我想实现一个应用程序,在发生事件时锁定我在Windows 10上打开的会话。我看到了或多或少相同的问题here,答案似乎说,没有办法以编程方式锁定Windows屏幕。但是,我已经看到一些应用程序会锁定Windows屏幕(例如,Nymi Companion Device Application)。在C#中锁定Windows 10屏幕(UWP和SDK)

你知道如何实施储物柜吗?或者哪个模块允许完成任务?

+1

您尝试和发送键组合'WIN + L' –

+0

你尝试LockWorkStation();在 – saeed

+0

之前你可以运行rundll32.exe user32.dll,LockWorkStation - 我确定有其他人 – BugFinder

回答

0

这工作:

using System.Runtime.InteropServices; 

[DllImport("user32.dll")] 
public static extern void LockWorkStation(); 
+0

Avo,我确实尝试过这个功能,但是它总是返回false并且Windows屏幕保持解锁状态。我正在使用Windows 10 SDK和UWP –

0

这是在C#中一个完整的示例代码

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 
using System.Runtime.InteropServices; 



namespace WindowsFormsApplication1 
{ 
    public partial class Form1 : Form 
    { 
     [DllImport("user32.dll")] 
     public static extern bool LockWorkStation(); 
     public Form1() 
     { 
      InitializeComponent(); 
     } 

     private void button1_Click(object sender, EventArgs e) 
     { 
      LockWorkStation(); 
     } 
    } 
} 
+0

嗨,Saeed,谢谢。我确实尝试过,函数总是返回false。 –

+0

@TriVuKhac您是否尝试过'Process.Start(@“C:\ WINDOWS \ system32 \ rundll32.exe”,“user32.dll,LockWorkStation”);'? –

+0

是的,我做到了。这对于UWP不起作用。我们可以查看SecondaryAuthenticationFactorRegistration.IsDevicePresenceMonitoringSupported()函数和SecondaryAuthenticationFactorRegistration.RegisterDevicePresenceMonitoringAsync()函数......这是正确锁定会话的起点。 –