I have looked almost everywhere on the internet and I cannot find a way to download a file from the internet into a specific folder that works with VB.NET 2010. I would like to download a file called, for instance, example.txt, and download it into, for example, %HOMEDRIVE%%HOMEPATH%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup so that it will run automatically at system startup. All help is appreciated
Asked
Active
Viewed 8,210 times
2
-
1Wow, that would be perfect for malware! – jangeador Nov 01 '10 at 05:27
2 Answers
3
Guessing something based on...
Using webClient = New WebClient()
Dim bytes = webClient.DownloadData("http://www.google.com")
File.WriteAllBytes(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "MyFileName.ext"), bytes)
End Using
As for the startup, VB.NET has a pretty ease way to add Registry keys...
My.Computer.Registry.SetValue
To set something like HKEY_CURRENT_USER\Software\Microsoft\CurrentVersion\Run
UPDATE
How to: Create a Registry Key and Set Its Values in Visual Basic
http://msdn.microsoft.com/en-us/library/cy6azwf7(v=VS.100).aspx

Chris Baxter
- 16,083
- 9
- 51
- 72
-
The file is downloaded in bytes, and then you can store the data where ever you would like... modifed the example to get the specific special folder etc.. – Chris Baxter Nov 01 '10 at 01:49
-
use 'Environment.SpecialFolder.Startup' to get the starup folder – Vishnu Pradeep Nov 01 '10 at 02:14
-
here it is for VBA https://stackoverflow.com/questions/17877389/how-do-i-download-a-file-using-vba-without-internet-explorer – giorgio79 Jun 19 '18 at 09:28
0
I would suggest using WebClient.DownloadFile. Use Environment.SpecialFolder.Startup to get the path to save the file.
Sub Main()
Using wc As New WebClient()
Dim startupPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup)
wc.DownloadFile("http://MyDomain.com/MyFile.txt", Path.Combine(startupPath, "test.txt"))
End Using
End Sub

Brian
- 37,399
- 24
- 94
- 109