Here's my code:
Code:
Dim sDirName As String
sDirName = "C:\Documents and Settings\All Users\Start Menu\Programs\Startup\"
Dim dDir As New DirectoryInfo(sDirName)
If Not dDir.Exists Then
My.Computer.FileSystem.CopyFile(Application.ExecutablePath, "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\" & appname)
Else
My.Computer.FileSystem.CopyFile(Application.ExecutablePath, "C:\Documents and Settings\All Users\Start Menu\Programs\Startup\" & appname)
End If
First, it checks if the user is running Vista, if they are then it copies itself to the vista startup location, if not then it copies itself to the XP startup location.
The problem is that when the user logs on the second time or runs the program twice, they'll get a .Net framework error saying that the program already exists, because it tries to copy to startup again. Is there any way I can add a line of code basically making it okay to overwrite itself or make it ignore/hide .net errors?
Thankyou!
R.