0

我只是想触发一个将程序复制到 Startup 文件夹的事件。我不明白我哪里出错了?我不断收到异常消息。正在复制的文件未在使用中。

 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
4

1 回答 1

1

现在,您正在创建一个FileInfofrom a folder,而不是一个file

这应该是:

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

或者,更简单:

Dim source = Path.Combine(StartupFolder, "doessomething.bat")
Dim target = Path.Combine(DesktopLink, "doessomething.bat")
File.Copy(source, target)
于 2013-08-13T20:55:38.280 回答