Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I've been playing around with the registry trying to get my countdown app to start when Windows does. It starts fine but when it runs, Windows looks for the text file with the clock info in c:\windows\system32 and then crashes as it can't find it. Running the app from its directory works fine though. Originally I thought it was because I was not setting the registry value with quotes. Here's how I'm setting the value:

VB
Dim KeyName As String = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run"
                   Dim valueName As String = "Date Countdown"
                   Dim value As Object = Chr(34) & Environment.CurrentDirectory & "\Date Countdown.exe" & Chr(34)

                   Registry.SetValue(KeyName, valueName, value)
Posted

Ok so first I think its probably a permissions problem.
Is the text file with the clock info a file you create your self? If so do not store it in C:\Windows\System32 instead store it in your users application data directory. The path to that directory can be found using the following:

VB
'for current user
Dim path As String = 
    Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
'or for all users
Dim path As String = 
    Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)


That way you can be sure there will be no permission problems.

Also I would change this code
VB
Dim value As Object = Chr(34) & Environment.CurrentDirectory &"\DateCountdown.exe" & Chr(34)


to this
VB
Dim value As String = Application.ExecutablePath

Just to make it cleaner.
 
Share this answer
 
v5
Seriously?

Why not use the Startup Folder?
Just put the pointer to the app there, then, once windows starts, it will call automatically.

It is the simplest thing to do.

Start
All Programs
Startup
Open


Then drag the app to it.


Et voila, it will start automatically.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900