Results 1 to 6 of 6

Thread: [RESOLVED] Load application at startup

  1. #1
    Dorothy
    Guest

    Resolved [RESOLVED] Load application at startup

    I need to Load application at startup of windows?

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Add the path and exe file to the Run Value of the Software/Microsoft/Windows/CurrentVersion key of the registry.

    VB Code:
    1. Dim regKey As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True)
    2. regKey.SetValue(Application.ProductName, Application.ExecutablePath)

    I used the CurrentUser here but you can also use LocalMachine if you want it to load regardless of who the user is.

  3. #3
    Addicted Member
    Join Date
    Apr 2003
    Location
    Australia
    Posts
    252
    At last in the 4th page of my Search Results, I found the thread which I was looking for.

    Can you guys please show me a sample code on how to use the above code?

    I tried this: (you will see what I am trying to do: I am trying make it as feature that the user can turn on and off).

    VB Code:
    1. Private Sub mnuToolsStartup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuToolsStartup.Click
    2.         mnuToolsStartup.Checked = Not mnuToolsStartup.Checked
    3.         If mnuToolsStartup.Checked = True Then
    4.             Dim regKey As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True)
    5.             regKey.SetValue(Application.ProductName, Application.ExecutablePath)
    6.         Else
    7.             Dim regKey As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True)
    8.             regKey.SetValue("")
    9.         End If
    10.     End Sub

    But it keeps saying Type 'RegistryKey' is not defined.

    Appreciate your help,
    Learning something new everyday!

    McoreD

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Put this at the very top of your class file .
    VB Code:
    1. Imports Microsoft.Win32

  5. #5
    Addicted Member
    Join Date
    Apr 2003
    Location
    Australia
    Posts
    252

    Thumbs up Excellent!

    Thank you very much Pirate!

    VB Code:
    1. Private Sub mnuToolsStartup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuToolsStartup.Click
    2.         mnuToolsStartup.Checked = Not mnuToolsStartup.Checked
    3.         If mnuToolsStartup.Checked = True Then
    4.             Dim regKey As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True)
    5.             regKey.SetValue(Application.ProductName, Application.ExecutablePath)
    6.         Else
    7.             Dim regKey As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True)
    8.             regKey.DeleteValue(Application.ProductName, False)
    9.         End If
    10.     End Sub

    With that Imports Microsoft.Win32 I was able uncover DeleteValue.
    And the above code just the job exactly how I want.

    Thanks again,
    McoreD

    P.S: How we are supposed to know codes like Imports Microsoft.Win32 ?

  6. #6
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    You're welcome . .
    By browsing Namespaces 'Hit Ctrl + Alt + J' in the Object Browser .
    Imports keyword isn't nothing than a way to shortcut some lengthy path to namespaces and classes .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width