Click here to Skip to main content
15,399,440 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So I am relatively new to C# (I know the basics and I coded in python before)
And I wrote a simple Installer Launcher.

C#
           using (var client = new WebClient())
           {
               string link = client.DownloadString("https://pastebin.com/raw/Lxwh1sNf");
               client.DownloadFile(link, "C:\\Programs\\GameBase\\Agent64.exe");
           }
Process.Start("C:\\Programs\\GameBase\\Agent64.exe");

So what this code does is getting a direct download Mediafire Link from Pastebin, Installs it and runs the downloaded exe. my problem is that the Program freezes everytime at the download. What can I do to solve this?

I would be happy about every help and maybe even a little code

What I have tried:

I have searched on Google for help but I havent found anything so far
Posted
Updated 13-Mar-21 23:59pm
Comments
Gerry Schmitz 13-Mar-21 13:49pm
   
You usually can't just update a "system folder" (i.e. Programs); try another folder.
BlackBirdTV 15-Mar-21 4:31am
   
And which one?

Your webhosting does not support direct links. it indirectly serves the file trough javascript, and validates wheter the client is a real browser or not.

if not a real browser, it serves you a infinite file at slow speed, causing your program to freeze.

also.

i would advice to write paths the following way
C#
@"C:\programs\"... instead of "this\gets\very\annoying"


also keep in mind that the windows defender AI, will find it very very suspicious that you are getting executables from the web to disk. most of your users will get to deal with warnings and also automatic uninstallations. and you will not know about it, because windows is hiding that behaviour from its creator.

also, writign a file to programs folder might require permissions that you need to ask for (process elevation). secondly, he might not grant it to your app.
   
Comments
BlackBirdTV 14-Mar-21 7:10am
   
I use a German windows and Programs isn't a sys folder here, but thanks for these infos
BlackBirdTV 14-Mar-21 8:13am
   
But what folders can I use to Run my exe from?
   
Comments
BlackBirdTV 14-Mar-21 7:10am
   
I guess I shall use DownloadFileAsync?

Edit: I get a exe that is "not valid for this os", how vs says
RickZeeland 14-Mar-21 7:15am
   
Yes, this way your UI thread will remain responsive, it is recommend to study Async first if you never used it, there are many pitfalls.
BlackBirdTV 14-Mar-21 7:26am
   
So i found a part of the problem: Mediafire changes the link every 12 hours or so. Thanks for you help!

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