Skip to content

Instantly share code, notes, and snippets.

@SamKr
Last active January 6, 2020 14:02
Show Gist options
  • Select an option

  • Save SamKr/4e225daa217256d8ead7599cb532a4ee to your computer and use it in GitHub Desktop.

Select an option

Save SamKr/4e225daa217256d8ead7599cb532a4ee to your computer and use it in GitHub Desktop.
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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment