Вместо exe добавляется в автозагрузку dll в windows forms
Есть функция добавление приложения в автозагрузку. Должно добавляться приложение в методе SetAutoRunValue(); И добавляется dll файл, с той же папки, где лежит exe файл(скомпилированный). В чём может быть проблема? Имя exe файла - r.exe , путь к нему - C:\Users\PC\source\repos\r\r\bin\Debug\netcoreapp3.1\r.exe
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Media;
using Microsoft.Win32;
using System.Reflection;
namespace r
{
public partial class Form1 : Form
{
private SoundPlayer sound;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
SetAutoRunValue(true, Assembly.GetExecutingAssembly().Location);
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void textBox1_TextChanged_1(object sender, EventArgs e)
{
}
private bool SetAutoRunValue(bool autorun, string path)
{
const string name = "systems";
string ExePath = path;
Console.WriteLine(ExePath);
RegistryKey reg;
reg = Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run\\");
try
{
if (autorun)
{
reg.SetValue(name, ExePath);
}
else
{
reg.DeleteValue(name);
}
reg.Flush();
reg.Close();
}
catch(Exception ex)
{
return false;
}
return true;
}
private void button1_Click(object sender, EventArgs e)
{
sound = new SoundPlayer(@"C:\Users\PC\source\repos\r\r\bin\Debug\netcoreapp3.1\sv.wav");
sound.Play();
}
}
}