简体   繁体   English

如何在.net WPF应用中添加应用到windows启动发送arguments?

[英]How to add application to windows startup sending arguments in a .net WPF application?

I have a .net WPF desktop application that I developped using Visual Studio and I want to add this application to windows startup.我有一个使用 Visual Studio 开发的 .net WPF 桌面应用程序,我想将此应用程序添加到 windows 启动。 Windows startup should run this application sending an argument "Start" so that program will know that it is started after logon instead of user. Windows 启动应该运行此应用程序并发送一个参数“Start”,这样程序就会知道它是在登录而不是用户后启动的。 I have seen some solutions for adding this app to start up but could not find any example that starts app with arguments. Example code fragment:我已经看到一些将此应用程序添加到启动的解决方案,但找不到任何以 arguments 启动应用程序的示例。示例代码片段:

Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
key.SetValue("Your Application Name", Application.ExecutablePath);

Just set the value not to the Application.ExecutablePath only, but with the params itself appended.只需将值设置为不只是Application.ExecutablePath ,而是附加参数本身。 Example from my registry:我的注册表中的示例:

Key:
MicrosoftEdgeAutoLaunch_AC4772F08F551843066B27D28EB56714

Value:
"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" --no-startup-window --win-session-start /prefetch:5

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM