[C#/WPF] 사용자가 로그인/로그아웃, PC를 종료할 때 뭔가를 하고 싶다
⇒ h tps:// 퀵했다. 작은 m / 절 1707 / MS / 4f입니다 73D86 그림 d283 그림 C4f
하고 싶은 일
앱 기동중에, 아래와 같은 조작으로 유저가 셧다운이나 로그오프등을 했을 때, 또 그 반대의 로그인 다시 한번 등에, 어플리 측에서 그것을 알고, 어떠한 처리를 하고 싶다. (무언가의 서버나 디바이스와 통신하는 앱이라면 일단 통신을 끝내거나 반대로 재개하고 싶다)


방법
SystemEvents
에 있는 각종 이벤트를 이용한다.
↓이 근처를 사용한다.

→ MS 자료
실험 코드
실험 코드 발췌.cs// 何のイベントハンドラが動いたのか、またイベントのArgの中身を表示する。
private void root_Loaded(object sender, RoutedEventArgs e)
{
SystemEvents.SessionSwitch += ((sender, e) => { AddLog("SessionSwitch :" + e.Reason.ToString()); });
SystemEvents.SessionEnding += ((sender, e) => { AddLog("SessionEnding :" + e.Reason.ToString()); });
SystemEvents.SessionEnded += ((sender, e) => { AddLog("SessionEnded :" + e.Reason.ToString()); });
SystemEvents.PowerModeChanged += ((sender, e) => { AddLog("PowerModeChanged :" + e.Mode.ToString()); });
SystemEvents.EventsThreadShutdown += ((sender, e) => { AddLog("EventsThreadShutdown:" + e.ToString()); });
}
실험 앱 사양:
어플을 기동한 채로, 셧다운이나 로그 오프 하면, 화면 표시&exe와 같은 계층에 로그를 출력해 주는 구조. (ListBox에 로그를 하고, 어떤 이벤트가 왔는지 보려고 했지만, 그것이라고 종료나 로그아웃했을 때에 실험 앱이 끝나 버려, 볼 수 없기 때문에, 로그 파일을 남기도록 했다)
잠금, 다시 로그인
잠그고 다시 로그인하면 어떻게 되나요?

결과SessionSwitch
이벤트에서 e.Reason
가 SessionLock
→ SessionUnlock
가 왔다.

다른 사용자를 전환하고 돌아온다.
다른 사용자로 전환하고 다시 사용자에게 돌아옵니다 (다시 로그인)
(=FUS(Fast User Switching)→한 사용자가 로그인한 채 다른 사용자도 로그인한 이미지)

결과SessionSwitch
이벤트에서 다음 순서로 왔다. (아래에서 순서대로)

※이번은 자신의 PC로 직접 유저 전환 조작을 실시했지만, 만약 이것이 리모트 데스크탑으로의 접속이라면, ConsoleConnect
와 ConsoleDisconnect
가, RemoteConnect
로그아웃(로그아웃, 로그오프라고도 함)
로그아웃합니다.

결과RemoteDisconnect
의 SessinEnding
와 그 후에 Logoff
의 SessinInded
가 왔다.

수면, 복귀 (일시 중지, 재개라고도 함)
수면.

결과
다음 순서로 왔다. (아래에서 순서대로)

셧다운
종료합니다.

결과Logoff
의 SessionEnding
의 후에, SystemShutdown
의 SessionEnded
이 왔다.

참고
SystemEvents.PowerModeChanged 이벤트
htps : // / cs. 미 c 로소 ft. 이 m / 그럼 jp / t t t / 아피 / 미 c로소 ft. 흠 32. sys 테메 〇 ts. Pour r도 짱 d?ぃ え w = t t t p t t x x 3.1
상기 페이지의 좌측에, 이벤트가 일람이 되어 있으므로, 거기로부터 필요한 이벤트에 날 수 있다.

이벤트 인수를보고 자세한 정보 (예 : SessionSwitch의 경우 suspend인지, resume인지 등)를 알아야합니다. 에의 링크가 실려 있으므로, 거기로부터 날아, 인수를 조사하면 된다.
Reference
이 문제에 관하여([C#/WPF] 사용자가 로그인/로그아웃, PC를 종료할 때 뭔가를 하고 싶다), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/tera1707/items/e7b4df031b750d0663c6
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
SystemEvents
에 있는 각종 이벤트를 이용한다.↓이 근처를 사용한다.

→ MS 자료
실험 코드
실험 코드 발췌.cs// 何のイベントハンドラが動いたのか、またイベントのArgの中身を表示する。
private void root_Loaded(object sender, RoutedEventArgs e)
{
SystemEvents.SessionSwitch += ((sender, e) => { AddLog("SessionSwitch :" + e.Reason.ToString()); });
SystemEvents.SessionEnding += ((sender, e) => { AddLog("SessionEnding :" + e.Reason.ToString()); });
SystemEvents.SessionEnded += ((sender, e) => { AddLog("SessionEnded :" + e.Reason.ToString()); });
SystemEvents.PowerModeChanged += ((sender, e) => { AddLog("PowerModeChanged :" + e.Mode.ToString()); });
SystemEvents.EventsThreadShutdown += ((sender, e) => { AddLog("EventsThreadShutdown:" + e.ToString()); });
}
실험 앱 사양:
어플을 기동한 채로, 셧다운이나 로그 오프 하면, 화면 표시&exe와 같은 계층에 로그를 출력해 주는 구조. (ListBox에 로그를 하고, 어떤 이벤트가 왔는지 보려고 했지만, 그것이라고 종료나 로그아웃했을 때에 실험 앱이 끝나 버려, 볼 수 없기 때문에, 로그 파일을 남기도록 했다)
잠금, 다시 로그인
잠그고 다시 로그인하면 어떻게 되나요?

결과SessionSwitch
이벤트에서 e.Reason
가 SessionLock
→ SessionUnlock
가 왔다.

다른 사용자를 전환하고 돌아온다.
다른 사용자로 전환하고 다시 사용자에게 돌아옵니다 (다시 로그인)
(=FUS(Fast User Switching)→한 사용자가 로그인한 채 다른 사용자도 로그인한 이미지)

결과SessionSwitch
이벤트에서 다음 순서로 왔다. (아래에서 순서대로)

※이번은 자신의 PC로 직접 유저 전환 조작을 실시했지만, 만약 이것이 리모트 데스크탑으로의 접속이라면, ConsoleConnect
와 ConsoleDisconnect
가, RemoteConnect
로그아웃(로그아웃, 로그오프라고도 함)
로그아웃합니다.

결과RemoteDisconnect
의 SessinEnding
와 그 후에 Logoff
의 SessinInded
가 왔다.

수면, 복귀 (일시 중지, 재개라고도 함)
수면.

결과
다음 순서로 왔다. (아래에서 순서대로)

셧다운
종료합니다.

결과Logoff
의 SessionEnding
의 후에, SystemShutdown
의 SessionEnded
이 왔다.

참고
SystemEvents.PowerModeChanged 이벤트
htps : // / cs. 미 c 로소 ft. 이 m / 그럼 jp / t t t / 아피 / 미 c로소 ft. 흠 32. sys 테메 〇 ts. Pour r도 짱 d?ぃ え w = t t t p t t x x 3.1
상기 페이지의 좌측에, 이벤트가 일람이 되어 있으므로, 거기로부터 필요한 이벤트에 날 수 있다.

이벤트 인수를보고 자세한 정보 (예 : SessionSwitch의 경우 suspend인지, resume인지 등)를 알아야합니다. 에의 링크가 실려 있으므로, 거기로부터 날아, 인수를 조사하면 된다.
Reference
이 문제에 관하여([C#/WPF] 사용자가 로그인/로그아웃, PC를 종료할 때 뭔가를 하고 싶다), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/tera1707/items/e7b4df031b750d0663c6
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
// 何のイベントハンドラが動いたのか、またイベントのArgの中身を表示する。
private void root_Loaded(object sender, RoutedEventArgs e)
{
SystemEvents.SessionSwitch += ((sender, e) => { AddLog("SessionSwitch :" + e.Reason.ToString()); });
SystemEvents.SessionEnding += ((sender, e) => { AddLog("SessionEnding :" + e.Reason.ToString()); });
SystemEvents.SessionEnded += ((sender, e) => { AddLog("SessionEnded :" + e.Reason.ToString()); });
SystemEvents.PowerModeChanged += ((sender, e) => { AddLog("PowerModeChanged :" + e.Mode.ToString()); });
SystemEvents.EventsThreadShutdown += ((sender, e) => { AddLog("EventsThreadShutdown:" + e.ToString()); });
}
잠그고 다시 로그인하면 어떻게 되나요?

결과
SessionSwitch
이벤트에서 e.Reason
가 SessionLock
→ SessionUnlock
가 왔다.
다른 사용자를 전환하고 돌아온다.
다른 사용자로 전환하고 다시 사용자에게 돌아옵니다 (다시 로그인)
(=FUS(Fast User Switching)→한 사용자가 로그인한 채 다른 사용자도 로그인한 이미지)

결과SessionSwitch
이벤트에서 다음 순서로 왔다. (아래에서 순서대로)

※이번은 자신의 PC로 직접 유저 전환 조작을 실시했지만, 만약 이것이 리모트 데스크탑으로의 접속이라면, ConsoleConnect
와 ConsoleDisconnect
가, RemoteConnect
로그아웃(로그아웃, 로그오프라고도 함)
로그아웃합니다.

결과RemoteDisconnect
의 SessinEnding
와 그 후에 Logoff
의 SessinInded
가 왔다.

수면, 복귀 (일시 중지, 재개라고도 함)
수면.

결과
다음 순서로 왔다. (아래에서 순서대로)

셧다운
종료합니다.

결과Logoff
의 SessionEnding
의 후에, SystemShutdown
의 SessionEnded
이 왔다.

참고
SystemEvents.PowerModeChanged 이벤트
htps : // / cs. 미 c 로소 ft. 이 m / 그럼 jp / t t t / 아피 / 미 c로소 ft. 흠 32. sys 테메 〇 ts. Pour r도 짱 d?ぃ え w = t t t p t t x x 3.1
상기 페이지의 좌측에, 이벤트가 일람이 되어 있으므로, 거기로부터 필요한 이벤트에 날 수 있다.

이벤트 인수를보고 자세한 정보 (예 : SessionSwitch의 경우 suspend인지, resume인지 등)를 알아야합니다. 에의 링크가 실려 있으므로, 거기로부터 날아, 인수를 조사하면 된다.
Reference
이 문제에 관하여([C#/WPF] 사용자가 로그인/로그아웃, PC를 종료할 때 뭔가를 하고 싶다), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/tera1707/items/e7b4df031b750d0663c6
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
로그아웃합니다.

결과
RemoteDisconnect
의 SessinEnding
와 그 후에 Logoff
의 SessinInded
가 왔다.
수면, 복귀 (일시 중지, 재개라고도 함)
수면.

결과
다음 순서로 왔다. (아래에서 순서대로)

셧다운
종료합니다.

결과Logoff
의 SessionEnding
의 후에, SystemShutdown
의 SessionEnded
이 왔다.

참고
SystemEvents.PowerModeChanged 이벤트
htps : // / cs. 미 c 로소 ft. 이 m / 그럼 jp / t t t / 아피 / 미 c로소 ft. 흠 32. sys 테메 〇 ts. Pour r도 짱 d?ぃ え w = t t t p t t x x 3.1
상기 페이지의 좌측에, 이벤트가 일람이 되어 있으므로, 거기로부터 필요한 이벤트에 날 수 있다.

이벤트 인수를보고 자세한 정보 (예 : SessionSwitch의 경우 suspend인지, resume인지 등)를 알아야합니다. 에의 링크가 실려 있으므로, 거기로부터 날아, 인수를 조사하면 된다.
Reference
이 문제에 관하여([C#/WPF] 사용자가 로그인/로그아웃, PC를 종료할 때 뭔가를 하고 싶다), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/tera1707/items/e7b4df031b750d0663c6
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
종료합니다.

결과
Logoff
의 SessionEnding
의 후에, SystemShutdown
의 SessionEnded
이 왔다.
참고
SystemEvents.PowerModeChanged 이벤트
htps : // / cs. 미 c 로소 ft. 이 m / 그럼 jp / t t t / 아피 / 미 c로소 ft. 흠 32. sys 테메 〇 ts. Pour r도 짱 d?ぃ え w = t t t p t t x x 3.1
상기 페이지의 좌측에, 이벤트가 일람이 되어 있으므로, 거기로부터 필요한 이벤트에 날 수 있다.

이벤트 인수를보고 자세한 정보 (예 : SessionSwitch의 경우 suspend인지, resume인지 등)를 알아야합니다. 에의 링크가 실려 있으므로, 거기로부터 날아, 인수를 조사하면 된다.
Reference
이 문제에 관하여([C#/WPF] 사용자가 로그인/로그아웃, PC를 종료할 때 뭔가를 하고 싶다), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/tera1707/items/e7b4df031b750d0663c6
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
Reference
이 문제에 관하여([C#/WPF] 사용자가 로그인/로그아웃, PC를 종료할 때 뭔가를 하고 싶다), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/tera1707/items/e7b4df031b750d0663c6텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)