SamKr
12/3/2019 - 9:54 AM

Set Self in RunOnce

Adds the current exec to runonce

const string userRoot = "HKEY_CURRENT_USER";
const string subkey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce";
const string keyName = userRoot + "\\" + subkey;

var location = new Uri(Assembly.GetEntryAssembly().GetName().CodeBase);
var fileInfo = new FileInfo(location.AbsolutePath);
var fileLoc = fileInfo.FullName;
var fileDesc = Path.GetFileNameWithoutExtension(fileInfo.Name);

Registry.SetValue(keyName, fileDesc, fileLoc, RegistryValueKind.String);