發表文章

目前顯示的是 5月, 2021的文章

C# 讓電腦不要進入螢幕保護狀態 do not let windows into screen saver(lock)

圖片
 對不起,管理員 因為公司強迫要求使用者未使用電腦情況下,5分鐘要鎖定螢幕,由於是使用AD強制控制,所以使用者沒有辦法自己去關閉。 而我,因為常有需要參考畫面上的內容,在另外一部電腦操作,因此導致這部電腦一直會進入螢幕鎖定。超級麻煩又討厭。 所以開發了一隻小程式來防止Windows進入螢幕鎖定狀態。   程式下載(我只想使用): 這裡   密碼:radio-idea.blogspot.com   平台:.Net FrameWork 4.5   注意:可能會與軟體KVM衝突 這是利用Timer不斷偵測 Idle 時間 而這個 Idle 時間則是利用 GetLastInputInfo 取得鍵盤滑鼠輸入的最後時間計算與現在的時間差得到的,當這個時間差超過預定檢測的時間(我的程式碼是設定4分鐘,因為進入螢幕鎖定是5分鐘)時,會去模擬滑鼠輸入動作,這個模擬動作是透過SendInput來達成,以上這些功能都是呼叫Windows API來處理。 由於Windows API是非託管程序(Unmanaged)因此得引用 using System.Runtime.InteropServices; 主程序: using  System; using  System.Windows.Forms; using  System.Runtime.InteropServices; using  System.Configuration; namespace  DONTSLEEP {      public partial class   Form1 : Form     {          public int  Idle_time = 240; //閒置秒數(4分鐘)          public int  CCount = 0;          public bool  shacking =  false ;                   public enum   MonitorState   : int         {             MONITOR_ON = -1,             MONITOR_OFF = 2,