我正在为自己制作一些桌面实用程序应用程序,我希望我的应用程序在每次系统启动时自动运行,我正在使用以下代码
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'
可能与您的系统权限设置有关。因此,请检查是否允许该应用程序或用户从Windows设置在该目标位置写入文件。
注册表值进行操作,您可以跳至SO的那个线程。
请记住以下注意事项:
Project Settings > View Windows Settings
,转到应用程序的清单,然后将level = "asInvoker"
更改为level = "requireAdministrator"
。