{REQ}C# Download And Run .reg Hide & URL

Discussion in 'Mixed Languages' started by AhrimanSefid, Apr 28, 2013.

  1. AhrimanSefid

    AhrimanSefid MDL Junior Member

    Apr 12, 2010
    97
    0
    0
    Hi All.
    Me Need Help For Make Exe C# Download And Run .reg Hide & URL.
    Thanks A lot.
     
  2. user_hidden

    user_hidden MDL Expert

    Dec 18, 2007
    1,026
    973
    60
    better explain yourself in English !
     
  3. stevemk14ebr

    stevemk14ebr MDL Senior Member

    Jun 23, 2010
    267
    48
    10
    your translation isn't so great you need to clarify your question
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,519
    7,100
    120
    #4 Josh Cell, Apr 30, 2013
    Last edited by a moderator: Apr 20, 2017
    If your question is about downloading and applying a registry file silently, I have coded this method in C#:

    Code:
            /*
    
             * DownloadAndInstallRegFile C# method by Michel Oliveira.
             * 2013/04/30
             * www.joshcellsoftwares.com 
             
             You may need to use these libraries on your project:
             
             System.Diagnostics;
             System.Net;
             System.IO;
             
             GPL License.
             
             */
    
            private static void DownloadAndInstallRegFile(string UriStr)
            {
                using (WebClient wbClient = new WebClient()) //Creating a new WebClient object in memory.
                {
                    string TempRegPth = Path.GetTempFileName() + ".reg"; //Define the temporary file for the downloaded file.
                    {
                        Console.WriteLine("Downloading the registry file online...");
                        wbClient.DownloadFile(UriStr, TempRegPth); //Download the file to a temp path created above.
                    }
                    Process pStart = new Process(); //Create a new Process object in memory.
                    {
                        Console.WriteLine("Applying the registry changes...");
                        {
                            pStart.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; //Set the WindowStyle to hidden for no prompt at the start
                            pStart.StartInfo.FileName = "REGEDIT.EXE"; //The RegEdit Windows tool for silently apply the reg change.
                            pStart.StartInfo.Arguments = "/S " + @"""" + TempRegPth + @""""; /*The arguments for the RegEdit tool. /S is the silent switch, 
                                                                                              * @"""" is the quotes for no errors at the app run action, 
                                                                                              * TempRegPth is the var with the temp downloaded file.*/
                            pStart.Start(); //Start the RegEdit tool.
                            pStart.WaitForExit(); //Wait for the RegEdit finish.
                        }
                        Console.WriteLine("Cleaning the temp file...");
                        {
                            if (File.Exists(TempRegPth)) //Check if the temp downloaded file is present.
                                File.Delete(TempRegPth); //Delete the temp file.
                        }
                    }
                    Console.WriteLine("Done! Press any key to exit from this application.");
                    Console.ReadKey(); //Pause the console application.
                }
            }
    Usage:

    Code:
    DownloadAndInstallRegFile("http://www.mynewwebsite.com/regfile/registryfile.reg"); //Your online file inside the quotes.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. Alphawaves

    Alphawaves Super Moderator/Developer
    Staff Member

    Aug 11, 2008
    5,873
    20,140
    180
    Good example.. nice to see you back here Josh..:hug2:
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. MrMagic

    MrMagic MDL Guru

    Feb 13, 2012
    5,706
    3,711
    180
    Sounds like OP is trying to create malware
     
  7. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,519
    7,100
    120
    Thanks bro. Now I will work with all the force on the next days. :hug2::hug2::hug2:
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. AhrimanSefid

    AhrimanSefid MDL Junior Member

    Apr 12, 2010
    97
    0
    0
    Thank You Very Good But Me Need 3 Server And 1 server down switch to server 2 or server 3.
     
  9. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,519
    7,100
    120
    #9 Josh Cell, May 1, 2013
    Last edited by a moderator: Apr 20, 2017
    For it, you need to check the server response with this method that I have coded:

    Code:
            /*
    
             * UriServerIsUp C# method by Michel Oliveira.
             * 2013/05/01
             * www.joshcellsoftwares.com 
             
             You may need to use these libraries on your project:
             
             System.Net;
             
             GPL License.
             
             */
    
            private static bool UriServerIsUp(string UriStr)
            {
                try //Try to do the check without errors.
                {
                    if (UriStr.ToUpper().StartsWith("FTP://")) //Check if the website procol are FTP.
                    {
                        FtpWebRequest fWebRequest = (FtpWebRequest)WebRequest.Create(UriStr); //Create a request using the Uri string received by the method.
                        fWebRequest.Timeout = 10000; //Set the response timeout to 10 seconds.
                        FtpWebResponse fWebResponse = (FtpWebResponse)fWebRequest.GetResponse(); //Get the server response.
                        if (fWebResponse.StatusCode == FtpStatusCode.OpeningData) //Get the server response code.
                        {
                            return true; //Return true if the response was 'OpeningData'.
                        }
                        else return false; //Return false if the response was not 'OpeningData'.
                    }
                    else //If is not FTP, check as HTTP protocol.
                    {
                        HttpWebRequest hWebRequest = (HttpWebRequest)WebRequest.Create(UriStr); //Create a request using the Uri string received by the method.
                        hWebRequest.Timeout = 10000; //Set the response timeout to 10 seconds.
                        HttpWebResponse hWebResponse = (HttpWebResponse)hWebRequest.GetResponse(); //Get the server response.
                        if (hWebResponse.StatusCode == HttpStatusCode.OK) //Get the server response code.
                        {
                            return true; //Return true if the response was 'OK'.
                        }
                        else return false; //Return false if the response was not 'OK'.
                    }
                }
                catch { return false; } //Return false if the there is an error with the request method.
            }
    Usage to check multiple websites using the 'UriServerIsUp' and 'DownloadAndInstallRegFile' methods:

    Code:
                foreach (string ServerUriString in 
                    new object[] { "http://myfirstwebsite.com/regfile.reg", "ftp://ftp.mynewftp.com/regfile.reg", "http://mythserver.com/regfile.reg" }) //Make a simple forearch to check if the servers is working.
                {
                    if (UriServerIsUp(ServerUriString)) //Check if the UriString has a valid status code.
                    {
                        DownloadAndInstallRegFile(ServerUriString); //Download and Install the registry file.
                        break; //Break the procedure one time that all the operation was completed successfully.
                    }
                }
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  10. AhrimanSefid

    AhrimanSefid MDL Junior Member

    Apr 12, 2010
    97
    0
    0
    #10 AhrimanSefid, May 28, 2013
    Last edited: May 28, 2013
    (OP)
    Plz Add New v Auto run in start win and auto dl file import reg send massage.
     
  11. AhrimanSefid

    AhrimanSefid MDL Junior Member

    Apr 12, 2010
    97
    0
    0
    Plz Help In Code.
    Very Thank You.
     
  12. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,519
    7,100
    120
    ? - Please learn about C# a bit more and try to do the things yourself. Will be good and you will learn some basic things instead of always ask for the full code around your development. :)

    Tip: You will need to use the Task Scheduler if your app needs of elevation around UAC activated systems.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...