Results 1 to 10 of 10

Thread: [RESOLVED] [2008] Run at startup

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Resolved [RESOLVED] [2008] Run at startup

    Hi, i'm having a little bit of trouble with making my application run at startup... I'm using this code:

    Code:
        Private Sub CheckBox5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox5.CheckedChanged
            If CheckBox5.Checked = True Then
                CheckBox6.Checked = False
                CheckBox6.Enabled = False
                Dim key As Microsoft.Win32.RegistryKey
                key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True)
                key.SetValue("To-Do List", Application.ExecutablePath)
                My.Settings.DefaultCheck5 = True
            ElseIf CheckBox5.Checked = False Then
                CheckBox6.Enabled = True
                Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True).DeleteValue("To-Do List", False)
                My.Settings.DefaultCheck5 = False
            End If
        End Sub
    So... What I'm doing is creating a registry value to make the program run at startup... Ok, so that works fine.... But, if i make some changes to a listbox that i have in there (saves the information in a text file), when it loads at startup, it doesnt load the newly-edited info, it loads the information when the registry value was first created, how can i prevent this from happening?
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2008] Run at startup

    It has nothing to do with the registry... You have to look in to your application code. Show us the code in your application's load event.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Re: [2008] Run at startup

    Code:
     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ListBox1.Items.Clear()
            'Sets the ListStarts variable to 0
            My.Settings.ListStarts = 0
            'Sets the CurrentUser to an empty string
            My.Settings.CurrentUser = ""
            'Sets the strings of some variables
            My.Settings.CurrentDirectory = Directory.GetCurrentDirectory.ToString
            'Checks to see if it's the first run of the program
            If My.Settings.FirstRun = True Then
                UserINFO.ShowDialog()
                My.Settings.FirstRun = False
            ElseIf My.Settings.FirstRun = False Then
                'Checks if the Settings folder exists
                If Directory.Exists(My.Settings.CurrentDirectory & "\Settings\Usernames") = False Then
                    Directory.CreateDirectory(My.Settings.CurrentDirectory & "\Settings\Usernames")
                End If
            End If
            'Handles the ToolTip delay
            Me.ToolTip1.ReshowDelay = 10
            Me.ToolTip1.InitialDelay = 1000
            'Handles fade-in effects
            If My.Settings.DisableFadeIn = True Then
                Timer1.Enabled = False
                Me.Opacity = 100
                ManageUsers.Timer1.Enabled = False
                ManageUsers.Opacity = 100
            ElseIf My.Settings.DisableFadeIn = False Then
                Timer1.Enabled = True
                ManageUsers.Timer1.Enabled = True
            End If
            'Settings from Customize form
            With Me
                .ListBox1.ForeColor = My.Settings.DefaultColor
                .FormBorderStyle = My.Settings.DefaultCustomBorder
                .Button1.Visible = My.Settings.DefaultButton1
                .Button2.Visible = My.Settings.DefaultButton2
                .Button3.Visible = My.Settings.DefaultButton3
                .Size = My.Settings.DefaultSize
                .ShowInTaskbar = My.Settings.ShowInTaskbar
            End With
            With Customize
                .CheckBox1.Checked = My.Settings.DefaultCheck1
                .CheckBox2.Checked = My.Settings.DefaultCheck2
                .CheckBox3.Checked = My.Settings.DefaultCheck3
                .CheckBox4.Checked = My.Settings.DefaultCheck4
                .CheckBox5.Checked = My.Settings.DefaultCheck5
                .CheckBox6.Checked = My.Settings.DefaultCheck6
                .CheckBox7.Checked = My.Settings.DefaultCheck7
            End With
            PrintSettings.Enabled = My.Settings.DefaultPrinterSettings
            'Settings end here
            ManageUsers.ShowDialog()
            TextBox1.Focus()
        End Sub
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2008] Run at startup

    Look at these lines
    Code:
            ListBox1.Items.Clear()
            'Sets the ListStarts variable to 0
            My.Settings.ListStarts = 0
            'Sets the CurrentUser to an empty string
            My.Settings.CurrentUser = ""
    You clear the listbox, set the ListStart setting to 0 and CurrentUser to "". There is no code showing you save these values but I assume that you do save them to My.Settings, you have to load these items with the values read from My.Settings, not set them toi default values like that.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Re: [2008] Run at startup

    Code:
            ListBox1.Items.Clear()
            'Sets the ListStarts variable to 0
            My.Settings.ListStarts = 0
            'Sets the CurrentUser to an empty string
            My.Settings.CurrentUser = ""
    Yeah, i used My.Settings.ListStarts = 0 as a global variable to initiate an "If" statement in another form, but i found out i shouldn't have used it, so i took it out.

    Anyways, it still doesnt load the text from the .txt file.....
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

  6. #6
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2008] Run at startup

    Where is your code to tell it to load the text from the text file? I don't see it in the form.load code you showed. If you want something to happens in the form.load event, you have to code it. It doesn't happen automatically for you.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  7. #7
    Fanatic Member Vectris's Avatar
    Join Date
    Dec 2008
    Location
    USA
    Posts
    941

    Re: [2008] Run at startup

    You could write a batch file to the startup folder, that's what I do.

    Code:
            My.Computer.FileSystem.WriteAllText(My.Computer.FileSystem.SpecialDirectories.Programs & "\Startup\YourProgram.bat", "@echo off" & ControlChars.NewLine & "start /D""" & My.Computer.FileSystem.CurrentDirectory & """ " & IO.Path.GetFileName(Application.ExecutablePath), False)
    If your problem is solved, click the Thread Tools button at the top and mark your topic as Resolved!

    If someone helped you out, click the button on their post and leave them a comment to let them know they did a good job

    __________________
    My Vb.Net CodeBank Submissions:
    Microsoft Calculator Clone
    Custom TextBox Restrictions
    Get the Text inbetween HTML Tags (or two words)

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Re: [2008] Run at startup

    Yes... I know i could write a batch file to make things easier, but i just don't want it to be "easy" to be taken off the list of programs that run at startup; that's why wanted to use the registry key to do that.

    But, if i use this code:

    Code:
                Dim key As Microsoft.Win32.RegistryKey
                key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True)
                key.SetValue("To-Do List", Application.ExecutablePath)
    Should i write another line so that the program runs like "normal"? 'Cuz i doesn't load the text files when i loads, it's just an empty list.
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Re: [2008] Run at startup

    OK, so i found why it isnt loading the text files... I don't know why, but when the program loads at startup (using the previous code) it thinks that the current directory is: "C:\Documents and Settings\%username%", and i don't have a single line of code that specifies that directory.

    So is it posible that, by using the registry key, the program assumes that that's its current directory? Even though i wrote that it should get the current directory when the user first uses the program?

    Anyhow... Why does the current directory change?
    Last edited by tassa; Mar 18th, 2009 at 10:29 AM. Reason: Trying to make myself more clear
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Re: [2008] Run at startup

    can anyone help me with this?
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

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