Last active
January 6, 2020 14:02
-
-
Save SamKr/4e225daa217256d8ead7599cb532a4ee to your computer and use it in GitHub Desktop.
Adds the current exec to runonce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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