C#在Windows启动时运行应用程序MINIMIZED

Ron*_*Ron 3 .net c# startup minimized

我在Windows启动时获得了以下代码来运行应用程序:

    private void SetStartup(string AppName, bool enable)
    {
        string runKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";

        Microsoft.Win32.RegistryKey startupKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(runKey);

        if (enable)
        {
            if (startupKey.GetValue(AppName) == null)
            {
                startupKey.Close();
                startupKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(runKey, true);
                startupKey.SetValue(AppName, Application.ExecutablePath.ToString());
                startupKey.Close();
            }
        }
        else
        {
            startupKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(runKey, true);
            startupKey.DeleteValue(AppName, false);
            startupKey.Close();
        }
    }
Run Code Online (Sandbox Code Playgroud)

有用.但我想让程序最小化(仅在Windows启动时).我没有找到工作代码/很好的解释如何做到这一点.你能帮我吗?

谢谢.

小智 12

你有没有尝试过

this.WindowState = FormWindowState.Minimized;
Run Code Online (Sandbox Code Playgroud)

如果你想在Windows启动时启动最小化,你可以在命令行中添加额外的参数myapp.exe --start-minimized,然后你可以解析这个参数并检测你是否需要启动最小化.