我得到了以下code运行在Windows启动时应用:
I got the following code to run the application at windows startup:
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();
}
}
它的工作原理。但我想程序启动最小化(在窗口只启动)。 我没有找到一个工作code /很好的解释如何做到这一点。 你能帮助我吗?
It works. but I want the program to start minimized (at windows startup only). I didnt find a working code / good explanation how to do it. Can you help me please?
感谢。
您是否尝试过
this.WindowState = FormWindowState.Minimized;
如果你想在Windows启动时以最小化启动只有你可以添加额外的参数,命令行,如程序myapp.exe --start最小化
,那么你可以分析这个参数,检测是否需要启动最小化或没有。
If you want to start minimized at windows startup only you can add extra argument to command line, like myapp.exe --start-minimized
, then you can parse this parameter and detect whether you need to start minimized or not.