放置快捷方式在用户的启动文件夹,开始使用Windows [英] placing a shortcut in user's Startup folder to start with Windows

查看:197
本文介绍了放置快捷方式在用户的启动文件夹,开始使用Windows的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想给我的用户的开始使用Windows选项。当用户选中此选项将放置一个快捷方式图标到启动文件夹中(未注册)。

I wanted to give my user an option for "Start with Windows". When user check this option it will place a shortcut icon into Startup folder (not in registry).

在Windows重新启动,它会自动加载我的应用程序。

On Windows restart, it will load my app automatically.

如何才能做到这一点?

推荐答案

您可以使用Enviroment.SpecialFolder枚举,但根据您的要求,你可能会着眼于创建一个Windows服务,而不是一个应用程序已经开始启动时。

you can use the Enviroment.SpecialFolder enum, although depending on your requirements you might looks at creating a windows service instead an app that has to start on startup.

File.Copy("shortcut path...", Environment.GetFolderPath(Environment.SpecialFolder.Startup) + shorcutname);

编辑:

File.Copy只是需要从一个文件,文件路径复制文件。在该段的关键是Enviroment.GetFolderPath(Enviroment.SpecialFolder.Startup)获得的启动文件夹路径复制到。

File.Copy just takes a file from and file to path to copy a file. The key in that snippet is Enviroment.GetFolderPath(Enviroment.SpecialFolder.Startup) getting the startup folder path to copy to.

您可以使用上面的code几种方式。如果你有一个安装项目,您的应用程序,你可以运行像这样的安装。另一种方式可能是,当应用程序启动它检查是否存在shorcut那里,把一个人也没有,如果没有(File.Exists())。

you could use the above code several ways. If you had an installer project for your app, you could run something like this on install. Another way could be when the app launches it checks if the shorcut exists there and puts one there if not (File.Exists()).

<一个href="http://stackoverflow.com/questions/234231/how-do-you-create-an-application-shortcut-lnk-file-in-c-or-net">Here是一个关于code也可以创建快捷方式的问题。

Here is a question about creating shortcuts in code also.

这篇关于放置快捷方式在用户的启动文件夹,开始使用Windows的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆