我正在编写一个类似于谷歌桌面的桌面应用程序,但使用我自己的vb.net 2008小工具,当用户将其安装到他们的计算机上以在启动时运行时,我如何才能使我的应用程序运行?
假设我的应用程序名为windowsAplication1,并且我使用的是windows XP,并且该程序将安装在C盘上?
发布于 2009-09-04 06:31:48
您可以使用以下代码将其添加到注册表中
My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True).SetValue(Application.ProductName, Application.ExecutablePath)您可以使用以下命令将其删除
My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True).DeleteValue(Application.ProductName)上面的代码会将其添加到所有用户。您可以在以下键中将其添加到当前用户中
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run或者,您可以在“启动”文件夹中添加一个指向您的应用程序的链接。
我建议你不要自动这样做,它可能会激怒用户。我讨厌应用程序自动将它们添加到Windows启动中。为用户提供在windows启动时运行该程序的选项。
发布于 2013-08-04 13:39:42
简单地使用以下代码:
Dim info As New FileInfo(application.startuppath)
info.CopyTo(My.Computer.FileSystem.SpecialDirectories.Programs + "\startup\myapp.exe")希望能有所帮助。
发布于 2013-09-19 21:11:52
您可以使用以下代码完成此操作
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' This is where you'll need to have the program
' set the check box to the previous selection that
' the user has set. It's up to you how you do this.
' For now, I'll set it as "unchecked".
CheckBox1.Checked = False
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' The following code is a rendition of one provided by
' Firestarter_75, so he gets the credit here:
Dim applicationName As String = Application.ProductName
Dim applicationPath As String = Application.ExecutablePath
If CheckBox1.Checked Then
Dim regKey As Microsoft.Win32.RegistryKey
regKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True)
regKey.SetValue(applicationName, """" & applicationPath & """")
regKey.Close()
Else
Dim regKey As Microsoft.Win32.RegistryKey
regKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True)
regKey.DeleteValue(applicationName, False)
regKey.Close()
End If
' Assuming that you'll run this as a setup form of some sort
' and call it using .ShowDialog, simply close this form to
' return to the main program
Close()
End Subhttps://stackoverflow.com/questions/1377537
复制相似问题