Startup Registry Problems

b3jsd73jfx

Active member
Joined
Mar 6, 2006
Messages
28
Programming Experience
1-3
Ok, I have a problem with my program running on windows startup. Normally when my program runs, the first thing it does is read from a text file and read all the lines. This works fine and gives no errors when I do it normally. But when I put the registry key in (HKCU\Software\Microsoft\Windows\CurrentVersion\Run) this is when the error occurs. The program loads up fine, but it doesn't read the text file at all. I get no variables from the files at all. Any ideas?
 
Have you got some code that displays how and where you load the file?
 
VB.NET:
[SIZE=2][COLOR=#0000ff]Public [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Main()
[/SIZE][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] reader [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] IO.StreamReader = IO.File.OpenText("v.dat")
checkinterval = reader.ReadLine
autoupdate = reader.ReadLine
Browser = reader.ReadLine
AutoCheck = reader.ReadLine
StartMin = reader.ReadLine
reader.Close()
[/SIZE][SIZE=2][COLOR=#0000ff]Catch[/COLOR][/SIZE][SIZE=2] ex [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Exception
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Writer [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] IO.StreamWriter = IO.File.CreateText("v.dat")
checkinterval = 900000
autoupdate = "no"
Browser = "c:\program files\internet explorer\iexplore.exe"
AutoCheck = [/SIZE][SIZE=2][COLOR=#0000ff]False
[/COLOR][/SIZE][SIZE=2]StartMin = [/SIZE][SIZE=2][COLOR=#0000ff]False
[/COLOR][/SIZE][SIZE=2]Writer.Close()
[/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Form1 [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Form1
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] StartMin = [/SIZE][SIZE=2][COLOR=#0000ff]True [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]Form1.Opacity = 0
Form1.ShowInTaskbar = [/SIZE][SIZE=2][COLOR=#0000ff]False
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2]Application.Run(Form1)
[/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
That's my sub main...
 
that could be because you're making a streamwriter object, then setting the variables, but never writing anything:

VB.NET:
checkinterval = 900000
autoupdate = "no"
Browser = "c:\program files\internet explorer\iexplore.exe"
AutoCheck = False
StartMin = False
Dim Writer As IO.StreamWriter = IO.File.CreateText("v.dat")
with writer
  .WriteLine(checkinterval)
  .WriteLine(autoupdate)
  .WriteLine(Browser)
  .WriteLine(AutoCheck.ToString)
  .WriteLine(StartMin.ToString)
  .Close()
End With
 
It's not that. The purpose of the writer in this case is just to create the file, it stores the variables later. My issue isn't writing to a file, it's reading from it.
 
Alright, thanks for that info and here's the problem I found. My program path is C:\Documents and Settings\Owner\Desktop\Temp\Xanga Check.exe. When I put the path in the registry, the path is correct. Now when I load up my computer, the message box that pops up says that it can't find "C:\Documents and Settings\Owner\v.dat". Any idea why it would try to load from that directory?

I put the message box inside the catch statement
 
As stated in the documentation for the path parameter:
"Relative path information is interpreted as relative to the current working directory."

The applications current working directory need not be the same as the directory the process was started from at any given time.
Use the Application.StartupPath to reference where the file is relative to the application executable (or a fixed path to somewhere else specific).
 
Back
Top