Google デスクトップに似たデスクトップ アプリケーションをプログラミングしていますが、vb.net 2008 を使用した独自のガジェットを使用して、ユーザーがコンピューターにアプリケーションをインストールして起動時に実行するときにアプリケーションを作成するにはどうすればよいですか?
アプリケーション名が windowsAplication1 で、Windows XP を使用していて、プログラムが C ドライブにインストールされるとします。
次のコードでレジストリに追加できます
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 の起動時にプログラムを実行するオプションを提供します。
このコードを簡単に使用します。
Dim info As New FileInfo(application.startuppath)
info.CopyTo(My.Computer.FileSystem.SpecialDirectories.Programs + "\startup\myapp.exe")
それが役に立てば幸い。
Imports Microsoft.Win32
...
Registry.SetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", Application.ProductName, Application.ExecutablePath, RegistryValueKind.String)
簡単な方法
Imports Microsoft.Win32
...
Dim regKey As RegistryKey
regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run",True)
regKey.SetValue(Application.ProductName, Application.ExecutablePath)
regKey.Close()
それが役に立てば幸い
以下のコードを使用してこれを行うことができます
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 Sub
このコードを試してみてください:-
FileCopy("Name.Ext", Environment.GetFolderPath(Environment.SpecialFolder.Startup) & "\Name.Ext")
ここ (Name.Ext) :-
Name - Your Application's name.
Ext - The Extension, it's of-course .exe
最もシンプルで使いやすいです。