2009-06-18 21 views
3

ユーザーがWindows(2000以降)を実行しているコンピュータを積極的に使用しているかどうかを検出します。私はスクリーンセーバーを使うことに頼らずにこれをしたいと思っています。ユーザーの存在を検出する

背景:ハントグループに所属する顧客サービス部門があり、「利用可能」である可能性があります。 「使用可能」の場合は、待ち行列に座るのではなく、電話にルーティングされます。電話機が内線番号で鳴っている間、インバウンド発信者は音楽を保持するのではなく「鳴っている」音声を聞きます。残念ながら、私たちはまた、昼食に出かけるか、またはその日のために出発するときに、「利用可能」から抜け出すことを忘れた担当者を抱えています。

最終結果は、おそらく.NET

任意の考えを使って書くことでしょうか?

+0

人がコンピュータから離れると、コンピュータをロックしますか? – Yoopergeek

答えて

0

低レベルのキーボード/マウスフックを追加するためにWindows APIを使用して、しばらくの間アクティビティがないときにマークを付けてから、アクティビティが再び開始されたときに使用可能にマークすることができます。

http://www.codeproject.com/KB/cs/globalhook.aspxには何かがありますが、C#にあります。

+0

これは私のGoogle検索で見つけられなかったものです。早速のご返事ありがとうございます! – smbarbour

+0

なぜGetLastInputInfo()で最後のユーザー活動時間を要求することができますか? – macbirdie

+0

@macbirdieなぜなら私はWindows APIに関する経験が全くないからです。 – MiffTheFox

2

ユーザーがワークステーションをロックしている場合、または何分のアイドル時間が経過してもグループポリシーが画面ロックを強制した場合、Windows APIを使用してWTSRegisterSessionNotificationWTSUnRegisterSessionNotificationを使用してセッション通知イベントを購読できます。セッションがロックされていることをアプリケーションに知らせるようにWindowsに要求すると、ユーザーが存在しないことを示すものとしてそのセッションを使用できます。

良い読書:http://support.microsoft.com/kb/310153

例:

private const int NOTIFY_FOR_THIS_SESSION = 0x0; 
private const int WM_WTSSESSION_CHANGE = 0x2B1; 
private const int WTS_CONSOLE_CONNECT = 0x1; 
private const int WTS_CONSOLE_DISCONNECT = 0x2; 
private const int WTS_SESSION_LOCK = 0x7; 
private const int WTS_SESSION_UNLOCK = 0x8; 
private const int WM_DESTROY = 0x2; 
private const int WM_ACTIVATEAPP = 0x1C; 

// The WTSUnRegisterSessionNotification function unregisters the specified 
// window so that the specified window receives no more session-change notifications. 
[DllImport("Wtsapi32.dll")] 
private static extern bool WTSUnRegisterSessionNotification(IntPtr hWnd); 

// The WTSRegisterSessionNotification function registers the specified 
// window to receive session-change notifications. 
[DllImport("Wtsapi32.dll")] 
private static extern bool WTSRegisterSessionNotification(IntPtr hWnd, Int32 dwFlags); 

// The PostQuitMessage function indicates to the system that a thread 
// has made a request to quit. The PostQuitMessage function is typically used in 
// response to a WM_DESTROY message. 
[DllImport("user32.dll")] 
private static extern void PostQuitMessage(Int32 nExitCode); 

[DllImport("user32.dll", CharSet = CharSet.Auto)] 
public static extern IntPtr PostMessage(HandleRef hwnd, int msg, int wparam, int lparam); 

private void Unsubscribe() { 
    if (this.Handle != IntPtr.Zero) { 
     WTSUnRegisterSessionNotification(this.Handle); 
    } 
} 

private void Subscribe() { 
    if (this.Handle != IntPtr.Zero) { 
     WTSRegisterSessionNotification(this.Handle, NOTIFY_FOR_THIS_SESSION); 
    } 
} 

// override WndProc in order to catch process the Session-Notification events: 
protected override void WndProc(ref Message m) { 
    switch (m.Msg) { 
     case WM_WTSSESSION_CHANGE: 
     switch (m.WParam.ToInt32()) { 
      case WTS_CONSOLE_CONNECT: 
       // User-switch : Sign-on 
       break; 
      case WTS_CONSOLE_DISCONNECT: 
       // User-switch : Sign-off 
       break; 
      case WTS_SESSION_LOCK: 
       // Screen Lock 
       break; 
      case WTS_SESSION_UNLOCK: 
       // Screen Unlock 
       break; 
      default: 
       break; 
     } 
     break; 
     default: 
     break; 
    } 

    base.WndProc(ref m); 
} 
+0

申し訳ありませんが、質問はVB.NETのタグが付いているときはC#のコードです... – Yoopergeek

+0

ここで(http://www.developerfusion.com/tools/convert/csharp-to-vb/)それを変換するのは簡単ですVB.NET。人々はある言語から別の言語への変換を恐れるべきではありません。 (その機能は他の言語でもサポートされていると仮定します) – beach

+0

ところで、それは素晴らしい答えです。 – beach

関連する問題