Results 1 to 20 of 20

Thread: Wrong Directory Path at startup

Threaded View

  1. #1

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

    Wrong Directory Path at startup

    Hello,
    I'm using this code to make my app. run at startup if a CheckBox is checked

    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
    However, when the app. starts it loads some text to a ListBox. But, when the app. run at startup it creates a directory in:

    C:\Documents and Settings\%userprofile%\%app. folder%

    and its supposed to load the text from

    Directory.GetCurrentDirectory.ToString & "\My Program\textfile.txt"

    This is my FormLoad code:

    Code:
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ListBox1.Items.Clear()
            'Sets the CurrentUser to an empty string
            My.Settings.CurrentUser = ""
            'Gets the curent directory of the application
            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
    Last edited by tassa; Mar 25th, 2009 at 10:17 PM. Reason: Had posted the wrong code...
    "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