我想给我的用户一个select“从Windows启动”。 当用户选中此选项时,它会将快捷方式图标放入启动文件夹(不在registry中)。
在Windows重新启动时,它会自动加载我的应用程序。
如何才能做到这一点?
创build互斥锁时,“找不到path的一部分”错误
如何使用mono将.NET Windows Service应用程序迁移到Linux?
问题与Windows服务以编程方式重新启动自己
使用Console.WriteLine(C#)或printfn(F#)编写粗体文本?
win32 api是否过时了?
使用C ++检查客户端上的可用.NET框架
我有什么select使用C#在Windows Server上添加和删除IPSec策略?
您可以使用Enviroment.SpecialFolder枚举,虽然根据您的要求,您可能会考虑创建一个Windows服务,而不是一个必须在启动时启动的应用程序。
File.copy("shortcut path...",Environment.GetFolderPath(Environment.SpecialFolder.Startup) + shorcutname);
编辑:
File.copy只是从文件和文件到路径复制文件。 该片段中的关键是获取启动文件夹路径复制到Enviroment.GetFolderPath(Enviroment.SpecialFolder.Startup)。
你可以用几种方法使用上面的代码。 如果您的应用程序有安装程序项目,则可以在安装时运行此类程序。 另一种方式可能是当应用程序启动时检查shorcut是否存在,如果不存在则放一个(File.Exists())。
WshShell wshShell = new WshShell(); IWshRuntimeLibrary.IWshShortcut shortcut; string startUpFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup); // Create the shortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut( startUpFolderPath + "\" + Application.ProductName + ".lnk"); shortcut.TargetPath = Application.ExecutablePath; shortcut.WorkingDirectory = Application.StartupPath; shortcut.Description = "Launch My Application"; // shortcut.IconLocation = Application.StartupPath + @"App.ico"; shortcut.Save();
private void button2_Click(object sender,EventArgs e) { string pas = Application.StartupPath; string sourcePath = pas; string destinationPath = @"C:ProgramDataMicrosoftwindowsstart MenuProgramsstartup"; string sourceFileName = "filename.txt";//eny tipe of file string sourceFile = System.IO.Path.Combine(sourcePath,sourceFileName); string destinationFile = System.IO.Path.Combine(destinationPath); if (!System.IO.Directory.Exists(destinationPath)) { System.IO.Directory.CreateDirectory(destinationPath); } System.IO.File.copy(sourceFile,destinationFile,true); }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。