Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Windows启动时隐藏C#程序,而不是在正常打开程序时隐藏?_C#_Windows_Startup_Launch_System Tray - Fatal编程技术网

如何在Windows启动时隐藏C#程序,而不是在正常打开程序时隐藏?

如何在Windows启动时隐藏C#程序,而不是在正常打开程序时隐藏?,c#,windows,startup,launch,system-tray,C#,Windows,Startup,Launch,System Tray,我有一个(.NET)程序,在Windows启动时自动启动。但是,我不希望主GUI窗口显示(我会将其隐藏在托盘中) 但是,我当然希望当用户以正常方式从任务栏/quicklaunch打开程序时,窗口会显示出来 我可以使用什么代码来解决此问题 要添加用于在Windows重新启动时加载程序的注册表项,请执行以下代码: RegistryKey rk = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion

我有一个(.NET)程序,在Windows启动时自动启动。但是,我不希望主GUI窗口显示(我会将其隐藏在托盘中)

但是,我当然希望当用户以正常方式从任务栏/quicklaunch打开程序时,窗口会显示出来

我可以使用什么代码来解决此问题

要添加用于在Windows重新启动时加载程序的注册表项,请执行以下代码:

RegistryKey rk = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);

rk.SetValue(softwareName, Application.ExecutablePath.ToString());

在自动运行部分注册程序时,请附加命令行键,例如
/silent

在程序中,处理此键以隐藏自己


相关阅读:。

只需在启动快捷方式或注册表的运行键中添加一个命令行参数,如
/hidewindow


然后在
main(string[]args)
中检查
args.Any(a=>a==“/hidewindow”)
并且不显示窗口

我忘了说,当Windows重新启动时,我的程序从注册表中的一个键启动(以避免某些复杂情况)。我刚刚编辑了这个问题,以给出注册表项的代码,如果您可以在答案中充实一些代码的话……使用
Application.ExecutablePath.ToString()
,而不是
Application.ExecutablePath+“/hidewindow”
…非常有效,您的答案会因为代码而被勾选-谢谢!