Question

Just recently I've started with Microsoft Visual Basic 2010 Express and I am creating an application which loads a URL into the browser component.

One of the settings that the user is able to configure is to 'start the app when windows launches'. When this checkbox is checked and the user saves his preferences I create a shortcut in the microsoft startup folder so the application is ran when windows starts up.

I do so using the following code:

My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True).SetValue(Application.ProductName, Application.ExecutablePath)
Dim startup As String = Environment.GetFolderPath(Environment.SpecialFolder.Startup)
IO.File.Copy(Application.ExecutablePath, startup & "\ApplicationName.exe")

The problem is, than when I use the the shortcut that Visual Basic makes on install, located on the desktop or start menu programfolder, it loads the settings defined by the user. But when the shortcut from the startup folder is ran, it loads a completely 'new' application sort of, with all the settings on default.

Anybody that knows what I might be doing wrong? I've searched the internet alot and also looked on StackOverflow topics like copying app shortcut to startup folder VB (which didn't work for me)

Any help would be highly appreciated. If you need more info, please ask and I'll look it up asap.

Was it helpful?

Solution

you are not creating a shortcut, you are copying the executable file to the startup folder !! this copied executable won't find a config file near it so it will create a new one ! that's why it shows default values .. to make a shortcut import the "Windows Script Host object model" from the "COM" tab in project->refrences->add...

Dim oShell As IWshRuntimeLibrary.WshShell
Dim oShortCut As IWshRuntimeLibrary.WshShortcut

oShell = New IWshRuntimeLibrary.WshShell
oShortCut = oShell.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Startup) & _
                                                    "\" & GetFileName(Application.ExecutablePath) & ".lnk")
Dim s = Environment.GetFolderPath(Environment.SpecialFolder.Startup)
With oShortCut
    .TargetPath = Application.ExecutablePath
    .Arguments = ""
    .WorkingDirectory = GetDirectoryName(Application.ExecutablePath)
End With
oShortCut.Save()
oShortCut = Nothing : oShell = Nothing
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top