0
나는 완전히 활용되지 않는 것으로 알고있는 모바일 카트에 약 250 대의 랩톱이 있습니다. 전원을 켜고 이벤트를 종료하기 위해 로그 파일을 쓰는 프로그램을 작성 중입니다. 그러나, 즉각적인 종료 이벤트를 잡으려고 할 때 (사용자가 전원 버튼을 누르고 있음) 텍스트 파일에 데이터가 기록되지 않습니다.PC 시작, 종료 및 치명적인 종료를 추적하는 방법
모든 입력 사항이 유용 할 것입니다. 미리 감사드립니다.
코드 :
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.IO;
using Microsoft.Win32;
namespace Log
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string CrLf = System.Environment.NewLine;
private static int WM_QUERYENDSESSION = 0x11;
private static int WM_ENDSESSION_CRITICAL = 0x40000000;
private static bool systemShutdown = false;
private void Form1_Load(object sender, EventArgs e)
{
Write_Data("[" + DateTime.Now.ToString() + "] " + "Power on");
}
protected override void WndProc(ref System.Windows.Forms.Message m)
{
if (m.Msg == WM_QUERYENDSESSION)
{
Write_Data("[" + DateTime.Now.ToString() + "] " + "Power off");
systemShutdown = true;
}
// If this is WM_QUERYENDSESSION, the closing event should be
// raised in the base WndProc.
if (m.Msg == WM_ENDSESSION_CRITICAL)
{
Write_Data("[" + DateTime.Now.ToString() + "] " + "Critical power down");
systemShutdown = true;
}
base.WndProc(ref m);
}
private void Write_Data(string str_Data)
{
using (StreamWriter output = new StreamWriter("../Log.txt", true))
{
output.WriteLine(str_Data);
}
}
}
}
저는 이것이 가장 실용적인 솔루션이라고 생각합니다. @djcrabhat – JMJ