Download .exe from MediaFire - vb.net

I am creating a project in VB, it has a files downloader, it works fine with files like .txt or images but when I try to download an .exe, the .exe turns to corrupted file.
I'm using this code:
My.Computer.Network.DownloadFile("http://www.mediafire.com/file/w9lk3emdczlb8hi/x_y_w_h.exe", "C:\Users\" & SystemInformation.UserName & "\Desktop\x_y_w_h.exe")
Process.Start("C:\Users\" & SystemInformation.UserName & "\Desktop\x_y_w_h.exe")
Downloads the .exe from the mediafire and sets the Location path and after it it opens it with Process.Start but the .exe is corrupted

This might help you:
Dim savePath As String = "your_save_path" 'Remember to include the file_name.extension_name at the end of the save path
Dim WebClientDownload As New WebClient
WebClientDownload.DownloadFile("http://download1917.mediafire.com/breo3h1b14og/w9lk3emdczlb8hi/x_y_w_h.exe", savePath)
MsgBox("Download Complete.")
Remarks:
I had this problem in the past. You were trying to save the html web page as a .exe file as said by #DavidWilson.
To solve this, you have to find the direct download link, in this case, I right-clicked on the download button and then clicked on "copy link address". It's always a good idea to test if the link copied is functioning (some file hosting sites invoke a script to start the download, but mediafire isn't that tricky)

Related

vba word - find application on system and launch it

I have an application, user can install it on any folder in his/her computer how can I find my application on his computer(where it is installed and launch it)
Dim path
path = "path/to/myApplication.exe" 'path to myApplication is unknown I need to find it
Shell """" & path & """", vbNormalFocus
Is there any easy way I can find where user has installed my application on his computer, in windows
This SO Article offers a great solution to your problem.
You can always iterate recursively through the file system, but there are obvious downsides to this method (time, permissions, networks etc.).

Use external exe in VB.NET project

I have a VB.NET program (I am working on this program).
I want to include an "external" exe file with my application while creating setup, and distribute it along with my software. I want to copy "this exe" to the installation directory on user demand (when user clicks a button) using my software. I know I can add "this" exe as a "Resource" file but how can I copy it to the installation directory from "Resources"? How to access "this" exe after I create installer?
I tried this:
System.IO.File.Copy(My.Resources.abc, "C:\Users\LabOne\Desktop\abc.exe")
but this didn't work. Please Help.
You need to write the byte-data of the resource to a local filepath.
Dim resource As Byte() = My.Resources.File
Using fs As New FileStream("C:\file.exe", FileMode.Create, FileAccess.ReadWrite)
fs.Write(resource, 0, resource.Length)
End Using

How to download PDF from website and store in %appdata% with Visual Basic .NET

I have a PDF file hosted on a website. I would like my VB.NET program to retrieve the file/download it and store it somewhere in %appdata%. This could be in a folder of it's own like %appdata%/my_program if you want. How do I achieve this in my VB.NET program?
Thanks.
You can use WebClient.DownloadFile(Url,LocalPath) for downloading your PDF file and saving in a local path on your PC. The class is in System.Net Assembly.
Use this to download file:
Dim WC As New System.Net.WebClient
WC.DownloadFile(URL, FileName)
or
My.Computer.Network.DownloadFile(URL, FileName)
To save it in the %appdata% just use :
My.Computer.FileSystem.SpecialDirectories.AllUsersApplicationData
or
My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData

open .chm file from my.resources when a buttons clicked

I already have this code from another question on this website.
Help.ShowHelp(ParentForm,
("C:\Users\Beaudean\Desktop\Help.chm"),HelpNavigator.TableOfContents, Nothing)
That works fine except i need the location of the chm help file to point to "my.resources" where it exists because i need to install my program but in that code example it only works with strings?
Thanks you :)
You cannot make this work. The .chm help file viewer is an external program, hh.exe. It doesn't know anything about managed resources, it needs a .chm file on disk.
Setup your project so that the .chm file is available in your build directory. Project + Add Existing Item and pick your .chm file. Select the added file and set its Build property to Content (so it gets installed with the rest of your files) and its Copy to Output Directory to "Copy if Newer" (so it gets copied to your build directory).
And modify your code so it can always find that file:
Dim path = System.IO.Path.Combine(Application.StartupPath, "Help.chm")
Help.ShowHelp(ParentForm, path, HelpNavigator.TableOfContents)

how to execute a batch file using a relative path added to the project

i have created a batch file and have added it to the project using add items. Basically what i am aiming at is to execute this file on a button click action.
I am using System.Diagnostics.Process.Start("hello.bat") command to run this file
i have changed the build action to resource for this batch file.
But when i run this program, it is not able to locate the batch file.
I am required to give a relative path as the path my vary from machine to machine. how can i make this file accessable using a relative path?
Resource puts it inside of your EXE as data. You can google how to write a vb.net resource to a file, use the io tempfilename function to get a tempfile and use that (appending .bat), then run the batchfile from the name you gave it.
If you can ship the .bat with your EXE, this is convenient for debugging and production:
* Put the batchfile in the BIN subdir (debug or release) with your exe. May have to click 'show all files' in project explorer to see these dirs. Right click the .bat and pick 'include in project'. Don't make it a resource.
Run it using application.startuppath & "\" & batfilename. (application.startuppath is only in winforms. You can google 'how to get exe path in vb.net console app' etc. if you need another way).