首页 > 解决方案 > 访问启动文件夹被拒绝 vb .net,我试图将我的应用程序复制到启动文件夹,但它说访问被拒绝

问题描述

我正在为自己制作一些桌面实用程序我希望我的应用程序在每次系统启动时自动运行,我正在使用以下代码

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    Dim FileToCopy As String
    Dim NewCopy As String
    Dim appPath As String = Application.ExecutablePath
    FileToCopy = appPath
    NewCopy = My.Computer.FileSystem.SpecialDirectories.Programs + "\startup" & "\" & My.Application.Info.AssemblyName & ".exe"
    If System.IO.File.Exists(FileToCopy) = True Then
        If System.IO.File.Exists(NewCopy) Then
            'MsgBox("Already Exists")
            Exit Sub
        End If
        System.IO.File.Copy(FileToCopy, NewCopy)
        MessageBox.Show("File Copied")
    End If
End Sub'

标签: vb.netwinformsvisual-studio-2019

解决方案


ACCESS 问题可以通过运行具有管理权限的应用程序来解决。您需要为应用程序提供管理权限以读取和写入系统文件夹或注册表。转到应用程序清单

Project Settings > View Windows Settings and change level = "asInvoker" to level = "requireAdministrator"


推荐阅读