2017-09-13 49 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()函數......這是正確鎖定會話的起點。 –