Hello,
I'm having a problem with my startup code what im trying to do is when the window system closes and then restarts my app should run but i get this error you can see on my screenshot.
![Name: error.JPG
Views: 81
Size: 29.3 KB]()
I don't know why this is happening as the test.txt file should be on that path its ment to be in the same folder as the application.
can anyone help please this is the code below.
I'm having a problem with my startup code what im trying to do is when the window system closes and then restarts my app should run but i get this error you can see on my screenshot.
I don't know why this is happening as the test.txt file should be on that path its ment to be in the same folder as the application.
can anyone help please this is the code below.
VB.net 2010 Code:
Imports Microsoft.Win32 Public Class Form1 Inherits System.Windows.Forms.Form Dim w As IO.StreamWriter Dim r As IO.StreamReader Dim oReg As RegistryKey Public Shared Sub AddToStartup() Dim regkey As RegistryKey regkey = Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True) regkey.SetValue("Shourtcut", Application.ExecutablePath, RegistryValueKind.String) regkey.Close() End Sub Public Shared Sub deleteStartup() Dim regkey As RegistryKey regkey = Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True) regkey.DeleteValue("Shourtcut") regkey.Close() End Sub Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click lstURLS.Items.Add(txtUrl.Text) txtUrl.Text = "" End Sub Private Sub btnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemove.Click lstURLS.Items.Remove(lstURLS.SelectedItem) End Sub Private Sub lstURLS_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstURLS.DoubleClick System.Diagnostics.Process.Start(lstURLS.SelectedItem) End Sub Private Sub btnFinish_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFinish.Click Dim i As Integer w = New IO.StreamWriter("test.txt") For i = 0 To lstURLS.Items.Count - 1 w.WriteLine(lstURLS.Items.Item(i)) Next w.Close() If chkRunWindow.Checked = True Then AddToStartup() Else deleteStartup() End If Application.Exit() End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Try CheckOnStart() Catch ex As Exception Exit Sub End Try r = New IO.StreamReader("test.txt") While (r.Peek() > -1) lstURLS.Items.Add(r.ReadLine) End While r.Close() End Sub Private Sub CheckOnStart() Try oReg = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True) If oReg.GetValue("Shourtcut") <> "" Then chkRunWindow.Checked = True Else chkRunWindow.Checked = False End If Catch ex As Exception Exit Sub End Try End Sub End Class