|
-
Mar 16th, 2009, 11:18 AM
#1
Thread Starter
Fanatic Member
[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?
-
Mar 16th, 2009, 11:22 AM
#2
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 -
-
Mar 16th, 2009, 11:32 AM
#3
Thread Starter
Fanatic Member
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
-
Mar 16th, 2009, 12:06 PM
#4
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 -
-
Mar 16th, 2009, 01:41 PM
#5
Thread Starter
Fanatic Member
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.....
-
Mar 16th, 2009, 01:47 PM
#6
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 -
-
Mar 16th, 2009, 04:54 PM
#7
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)
-
Mar 18th, 2009, 07:47 AM
#8
Thread Starter
Fanatic Member
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.
-
Mar 18th, 2009, 08:01 AM
#9
Thread Starter
Fanatic Member
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
-
Mar 18th, 2009, 02:00 PM
#10
Thread Starter
Fanatic Member
Re: [2008] Run at startup
can anyone help me with this?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|