0

I am simply tyring to fire an event that copies a program to the Startup folder. I do not understand where I am going wrong? I keep on getting exception message. The file that is being copies is NOT in use.

 Try
        Dim DesktopLink As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
        Dim StartupFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.Startup)

 Dim info As New FileInfo(StartupFolder)
            info.CopyTo(DesktopLink + "\doessomething.bat")

    Catch ex As Exception
        MessageBox.Show("Error: Can not copy to startup folder")
    End Try
Benjamin Jones
  • 987
  • 4
  • 22
  • 50

1 Answers1

1

Right now, you're creating a FileInfo from a folder, not a file.

This should likely be:

Dim info As New FileInfo(Path.Combine(StartupFolder, "doessomething.bat"))
info.CopyTo(Path.Combine(DesktopLink, "doessomething.bat"))

Or, even easier:

Dim source = Path.Combine(StartupFolder, "doessomething.bat")
Dim target = Path.Combine(DesktopLink, "doessomething.bat")
File.Copy(source, target)
Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373