public static void SetAutoBootup(bool isAuto)
{
string fileName = ConfigCode.CLIENT_PROC_NAME;
string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName);
string startup = System.Environment.GetFolderPath(Environment.SpecialFolder.Startup);
string shortPath = Path.Combine(startup, ConfigCode.PRODUCT_NAME+ ".lnk");
if (!isAuto)
{
//不设置开机启动
if (File.Exists(shortPath))
{
File.Delete(shortPath);
}
}
else
{
//设置开机启动
if (Directory.Exists(startup))
{
Directory.CreateDirectory(startup);
}
IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(shortPath);
shortcut.TargetPath = filePath;
shortcut.WorkingDirectory = Path.GetDirectoryName(filePath);
shortcut.Arguments = "";
shortcut.Description = ConfigCode.PRODUCT_NAME;
shortcut.IconLocation = filePath + ", 0";
shortcut.Save();
}
winform 在开始菜单添加快捷方式实现开机自启动
最新推荐文章于 2024-11-18 13:35:26 发布