C#:
private void Form1_Load(object sender, EventArgs e)
{
string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); //appdata
string fileName = Process.GetCurrentProcess().MainModule.FileName; //текущее название исполняемого файла
string filename1 = "file"; // название файла после сохранения
string directory = @"\Microsoft\Windows\Start Menu\Programs\Startup\";
string pathFile = folderPath + directory + filename1 + @".exe";
if (System.IO.File.Exists(pathFile))
{
}
else
{
FileInfo fileInfo = new FileInfo(fileName);
fileInfo.CopyTo(string.Concat(folderPath, directory + filename1 + @".exe"), true);
}
}
Принцип: Запускается файл, в независимости от того, переименован ли он был, он переносится в %appdata%\Microsoft\Windows\Start Menu\Programs\Startup\Название файла.exe (Автозапуск). Если файл есть - ничего не происходит.
Просто выкладываю мой способ, жду критики, хочу улучшить код.