代码之家  ›  专栏  ›  技术社区  ›  Pollitzer

“shutdown.exe”会破坏应用程序设置

  •  1
  • Pollitzer  · 技术社区  · 6 年前

    private void Window_Closed(object sender, EventArgs e)
    {
        Properties.Settings.Default.WinMainLocationX = this.Left; // ok
        Properties.Settings.Default.WinMainLocationY = this.Top; // ok
        Properties.Settings.Default.WinMain_size = new Size(this.Width, this.Height); // crucial setting
        Properties.Settings.Default.WinMain_state = this.WindowState; // ok
    
        Properties.Settings.Default.Save();
    }
    

    我每天通过一个包含 C:\WINDOWS\system32\shutdown.exe /s /t 20 shutdown.exe 可以通过的命令行输入看到 shutdown /? .

    enter image description here

    如何保护应用程序设置不受 关闭.exe ?

    2 回复  |  直到 6 年前
        1
  •  1
  •   NineBerry    6 年前

    我认为问题是在最小化应用程序窗口的同时存储设置。在这种情况下,窗口的宽度和高度将为0。

    RestoreBounds

    Properties.Settings.Default.WinMainLocationX = this.RestoreBounds.Left; 
    Properties.Settings.Default.WinMainLocationY = this.RestoreBounds.Top;
    Properties.Settings.Default.WinMain_size = new Size(this.RestoreBounds.Width, this.RestoreBounds.Height);
    Properties.Settings.Default.WinMain_state = this.WindowState;
    

    这个问题的一些答案展示了使用WinAPI函数的另一种方法 GetWindowPlacement SetWindowPlacement :

        2
  •  0
  •   Pollitzer    6 年前

    添加 Environment.Exit(0)

    private void Window_Closed(object sender, EventArgs e)
    {
        Properties.Settings.Default.WinMainLocationX = this.Left; // ok
        Properties.Settings.Default.WinMainLocationY = this.Top; // ok
        Properties.Settings.Default.WinMain_size = new Size(this.Width, this.Height); // crucial setting
        Properties.Settings.Default.WinMain_state = this.WindowState; // ok
    
        Properties.Settings.Default.Save();
    
        Environment.Exit(0);
    }
    
    推荐文章