访问路径被拒绝 vb.net

Acess to the path is denied vb.net

为什么我会看到这条消息。我只是想添加应用程序以每次使用 windows 启动,然后它会弹出这条消息。

Access to the path .... is denied.

我用这个代码添加到startup

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
       Dim info As New FileInfo(Application.StartupPath)
       info.CopyTo(My.Computer.FileSystem.SpecialDirectories.Programs + "\startup\Apps.exe")
    End Sub

如果您希望您的应用程序在 windows 启动时启动,您可以使用注册表。

要将应用程序添加到系统,请使用此代码 -

Imports Microsoft.Win32
Public Sub RunAtStartup(ByVal ApplicationName As String, ByVal ApplicationPath As String)
    Dim CU As Microsoft.Win32.RegistryKey = Registry.CurrentUser.CreateSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run")
    With CU
        .OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True)

        .SetValue(ApplicationName, ApplicationPath)

    End With
End Sub

要使用该功能,只需执行 -

RunAtStartup(Application.ProductName,Application.ExecutablePath)