Furkan Karagulle

Furkan Karagulle

  • NA
  • 30
  • 3.3k

C# File Copy Problem V2

Dec 2 2020 9:15 PM
  1. static void ExeCopy()    
  2. {    
  3. if (!File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Microsoft\Windows\Start Menu\Programs\Startup\securpass.exe"))    
  4. {    
  5. File.Copy(Path.GetFileName(Application.ExecutablePath), Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Microsoft\Windows\Start Menu\Programs\Startup\securpass.exe");    
  6. }    
  7. }    
Hi, I'm trying to get a copy of my application to the launch folder.
However, although I did not get an error, my code block does not work and my file is not copied.
I would be happy if you could help.
  1. static void ExeCopy()    
  2. {    
  3.     RegistryKey registryKey = Registry.CurrentUser.OpenSubKey    
  4.     ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"true);    
  5.     registryKey.SetValue("test.exe", Application.ExecutablePath);        
  6. }    
I added the above code block to my project. But my problem persists. The code block is error free but doesn't work.
  1. static void ExeCopy()    
  2. {    
  3.     String path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);    
  4.     var SourcefilePath = Path.Combine(path, @"\Microsoft\Windows\Start Menu\Programs\Startup\test.exe");
  5. // Handles whether there is a `\` or not.      
  6.     if (File.Exists(SourcefilePath))    
  7.     {    
  8.         File.Copy(SourcefilePath, DestinationPath)    
  9.     }    
  10. }   
I've added the above code block to my project. I get an error in the DestinationPath section. What is DestinationPath?

Answers (1)