亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

以編程方式確定鎖定工作站的持續時間?

以編程方式確定鎖定工作站的持續時間?

縹緲止盈 2019-08-16 14:40:30
以編程方式確定鎖定工作站的持續時間?如何在代碼中確定機器鎖定的時間?C#之外的其他想法也是受歡迎的。我喜歡Windows服務理念(并已接受它)以簡化和清潔,但遺憾的是我不認為它在這種特殊情況下對我有用。我想在我的工作站上運行這個,而不是在家里(或者除了家庭之外,我想),但它被國防部嚴格控制了。實際上,這就是我自己滾動的部分原因。無論如何我會寫下來看看它是否有效。感謝大家!
查看完整描述

3 回答

?
湖上湖

TA貢獻2003條經驗 獲得超2個贊

我之前沒有找到過這個,但是從任何應用程序都可以連接SessionSwitchEventHandler。顯然你的應用程序需要運行,但只要它是:

Microsoft.Win32.SystemEvents.SessionSwitch += new Microsoft.Win32.SessionSwitchEventHandler(SystemEvents_SessionSwitch);void SystemEvents_SessionSwitch(object sender, Microsoft.Win32.SessionSwitchEventArgs e){
    if (e.Reason == SessionSwitchReason.SessionLock)
    { 
        //I left my desk
    }
    else if (e.Reason == SessionSwitchReason.SessionUnlock)
    { 
        //I returned to my desk
    }}


查看完整回答
反對 回復 2019-08-16
?
阿波羅的戰車

TA貢獻1862條經驗 獲得超6個贊

我將創建一個處理OnSessionChange事件的Windows服務(visual studio 2005項目類型),如下所示:

protected override void OnSessionChange(SessionChangeDescription changeDescription){
    if (changeDescription.Reason == SessionChangeReason.SessionLock)
    { 
        //I left my desk
    }
    else if (changeDescription.Reason == SessionChangeReason.SessionUnlock)
    { 
        //I returned to my desk
    }}

您在此時記錄活動的內容和方式取決于您,但Windows服務可以快速方便地訪問Windows事件,如啟動,關閉,登錄/退出以及鎖定和解鎖事件。


查看完整回答
反對 回復 2019-08-16
?
HUH函數

TA貢獻1836條經驗 獲得超4個贊

下面的解決方案使用Win32 API。在工作站被鎖定時調用OnSessionLock,并在解鎖時調用OnSessionUnlock。

[DllImport("wtsapi32.dll")]private static extern bool WTSRegisterSessionNotification(IntPtr hWnd,int dwFlags);[DllImport("wtsapi32.dll")]private static extern bool WTSUnRegisterSessionNotification(IntPtrhWnd);private const int NotifyForThisSession = 0; // This session onlyprivate const int SessionChangeMessage = 0x02B1;private const int SessionLockParam = 0x7;private const int SessionUnlockParam = 0x8;protected override void WndProc(ref Message m){
    // check for session change notifications
    if (m.Msg == SessionChangeMessage)
    {
        if (m.WParam.ToInt32() == SessionLockParam)
            OnSessionLock(); // Do something when locked
        else if (m.WParam.ToInt32() == SessionUnlockParam)
            OnSessionUnlock(); // Do something when unlocked
    }

    base.WndProc(ref m);
    return;}void OnSessionLock() {
    Debug.WriteLine("Locked...");}void OnSessionUnlock() {
    Debug.WriteLine("Unlocked...");}private void Form1Load(object sender, EventArgs e){
    WTSRegisterSessionNotification(this.Handle, NotifyForThisSession);}
    // and then when we are done, we should unregister for the notification
    //  WTSUnRegisterSessionNotification(this.Handle);


查看完整回答
反對 回復 2019-08-16
  • 3 回答
  • 0 關注
  • 801 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號