Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

VS 2010 error help please

$
0
0
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.

VB.net 2010 Code:
  1. Imports Microsoft.Win32
  2.  
  3. Public Class Form1
  4.     Inherits System.Windows.Forms.Form
  5.  
  6.     Dim w As IO.StreamWriter
  7.     Dim r As IO.StreamReader
  8.  
  9.     Dim oReg As RegistryKey
  10.  
  11.     Public Shared Sub AddToStartup()
  12.         Dim regkey As RegistryKey
  13.         regkey = Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True)
  14.         regkey.SetValue("Shourtcut", Application.ExecutablePath, RegistryValueKind.String)
  15.         regkey.Close()
  16.     End Sub
  17.  
  18.     Public Shared Sub deleteStartup()
  19.         Dim regkey As RegistryKey
  20.         regkey = Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True)
  21.         regkey.DeleteValue("Shourtcut")
  22.         regkey.Close()
  23.     End Sub
  24.  
  25.  
  26.     Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
  27.         lstURLS.Items.Add(txtUrl.Text)
  28.         txtUrl.Text = ""
  29.  
  30.     End Sub
  31.  
  32.     Private Sub btnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemove.Click
  33.  
  34.         lstURLS.Items.Remove(lstURLS.SelectedItem)
  35.  
  36.     End Sub
  37.  
  38.     Private Sub lstURLS_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstURLS.DoubleClick
  39.  
  40.         System.Diagnostics.Process.Start(lstURLS.SelectedItem)
  41.  
  42.     End Sub
  43.  
  44.     Private Sub btnFinish_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFinish.Click
  45.         Dim i As Integer
  46.         w = New IO.StreamWriter("test.txt")
  47.         For i = 0 To lstURLS.Items.Count - 1
  48.             w.WriteLine(lstURLS.Items.Item(i))
  49.         Next
  50.  
  51.         w.Close()
  52.  
  53.         If chkRunWindow.Checked = True Then
  54.             AddToStartup()
  55.         Else
  56.             deleteStartup()
  57.  
  58.         End If
  59.         Application.Exit()
  60.     End Sub
  61.  
  62.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  63.  
  64.         Try
  65.             CheckOnStart()
  66.         Catch ex As Exception
  67.             Exit Sub
  68.         End Try
  69.  
  70.         r = New IO.StreamReader("test.txt")
  71.         While (r.Peek() > -1)
  72.             lstURLS.Items.Add(r.ReadLine)
  73.         End While
  74.         r.Close()
  75.  
  76.     End Sub
  77.  
  78.  
  79.     Private Sub CheckOnStart()
  80.         Try
  81.             oReg = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True)
  82.             If oReg.GetValue("Shourtcut") <> "" Then
  83.                 chkRunWindow.Checked = True
  84.             Else
  85.                 chkRunWindow.Checked = False
  86.             End If
  87.         Catch ex As Exception
  88.             Exit Sub
  89.         End Try
  90.     End Sub
  91.  
  92.  
  93. End Class
Attached Images
 

Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>