Jhon Mann
Jhon Mann

Reputation: 41

Run program without form on windows startup

What basically i want is to show is:

notifyicon.visible = true

I mean to show a tray icon when the windows starts up but the program form should not be shown ,how could i achieve it ?

I got to know that by adding to registry you can run the program on startup example below

Dim regkey As RegistryKey
        regkey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", True)
        If (runonstartupToolStripMenuItem.Checked = True) Then
            ' Add the value in the registry so that the application runs at startup
            regkey.SetValue("Your Application Name", Application.ExecutablePath.ToString())
        Else
            ' Remove the value from the registry so that the application doesn't start
            regkey.DeleteValue("Your Application Name", False)
        End If

but this will run the whole program and will make form show up which i do not want unless user manually starts it.

Upvotes: 2

Views: 928

Answers (2)

Dũng IT
Dũng IT

Reputation: 2999

I am use checkbox to set and unset:

Private Sub cbStartup_CheckedChanged(sender As Object, e As EventArgs) Handles cbStartup.CheckedChanged
        Dim applicationName As String = Application.ProductName
        Dim applicationPath As String = Application.ExecutablePath

        If cbStartup.Checked = True 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
    End Sub

Test working on VS 2015 run on Windows 10 64Bit.

Upvotes: 0

codeDom
codeDom

Reputation: 1769

Add this code to your form:

 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      Me.Hide()                    ' <= Required
      Me.ShowInTaskbar = False     ' <= Required
      NotifyIcon1.Visible = True  
      NotifyIcon1.ShowBalloonTip(10000)
 End Sub

When the program opens when the windows starts it should open with a unique parameter, And when the unique parameter is found the form will be hidden, Conversely if the user opens the program, will not have the parameter and then the form can show.

Upvotes: 0

Related Questions